Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: encode is not a function #79

Open
alizarei95 opened this issue May 15, 2023 · 5 comments
Open

TypeError: encode is not a function #79

alizarei95 opened this issue May 15, 2023 · 5 comments

Comments

@alizarei95
Copy link

Hello there, I'm new in js. I've downloaded index.js from here : https://www.jsdelivr.com/package/npm/cbor-x?tab=files&path=dist

and imported in my js file like this :

import * as CBOR from './src/js/cborx.js'

but when I call CBOR.encode(data) it throws :

Uncaught (in promise) TypeError: CBOR.encode is not a function

How it can be fixed?

@kriszyp
Copy link
Owner

kriszyp commented May 15, 2023

Are you trying to do this in Node or in the browser? With Node, you would typically download it by using npm install cbor-x and then import ... from 'cbor-x'. If you are using this in the browser, are you using any module loader/bundler? (could be the same route based on what you are using).

@alizarei95
Copy link
Author

alizarei95 commented May 15, 2023 via email

@kriszyp
Copy link
Owner

kriszyp commented May 15, 2023

If you are using a platform that supports ESM, you should be able to directly import encode.js.

@alizarei95
Copy link
Author

You mean I just import encode.js?

@kriszyp
Copy link
Owner

kriszyp commented May 17, 2023

Yes, like import { encode} from './path/to/encode.js'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants