sdk
sdk copied to clipboard
Error importing sdk from nodejs in module env
sdk 6.3.1
node v20.6.1
package.json:
{
"type": "module"
}
index.js:
import dock from '@docknetwork/sdk'
errors:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'node_modules/@docknetwork/crypto-wasm-ts/lib/anonymous-credentials/presentation' imported from node_modules/@docknetwork/sdk/index.js
Did you mean to import @docknetwork/crypto-wasm-ts/lib/anonymous-credentials/presentation.js?
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'node_modules/@docknetwork/crypto-wasm-ts/lib/anonymous-credentials' is not supported resolving ES modules imported from node_modules/@docknetwork/sdk/index.js
Did you mean to import @docknetwork/crypto-wasm-ts/lib/anonymous-credentials/index.js?
...
That's an odd error, does node_modules/@docknetwork/sdk/node_modules/@docknetwork/crypto-wasm-ts exist?
The problem is the file extension is missed. And directory import is not allowed in module environment. See https://nodejs.org/api/esm.html#mandatory-file-extensions
Look like you are using some bundler (rollup?) in your projects and it hides and fixes this error.
It's very easy to reproduce:
mkdir test && cd test
echo '{"type":"module","dependencies":{"@docknetwork/sdk": "^6.5.1"}}' > package.json
echo 'import dock from "@docknetwork/sdk"' > index.js
npm install
node index.js
I would suggest to use babel, as even if the sdk itself as fully node module compatible there is no guarantee all child packages would be which can cause this error
I still get this error with the latest version, what is the official method to get sdk working on nodejs?