TypeError: encode is not a function
Opened this issue · 5 comments
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?
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).
If you are using a platform that supports ESM, you should be able to directly import encode.js.
You mean I just import encode.js?
Yes, like import { encode} from './path/to/encode.js'