You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project that is declared as ESM module (it has "type":"module") in package.json. When I import and try to use @sphereon/ssi-sdk-ext.did-resolver-key I get the error:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/projects/stackblitz-starters-6hjrdu/node_modules/nist-weierstrauss/lib/index.js from /home/projects/stackblitz-starters-6hjrdu/node_modules/@sphereon/ssi-sdk-ext.did-resolver-key/dist/drivers/secp256r1.js not supported.
Instead change the require of index.js in /home/projects/stackblitz-starters-6hjrdu/node_modules/@sphereon/ssi-sdk-ext.did-resolver-key/dist/drivers/secp256r1.js to a dynamic import() which is available in all CommonJS modules.
This is because the version of nist-weierstrauss that is used (v1.6.1), has only ESM builds available. This should be OK, but ssi-sdk-ext.did-resolver-key is distributing only CJS and the import it is making for the nist-weierstrauss uses the require statement. Importing ESM modules with require is not allowed.
As a workaround for my case I have downgraded the nist-weierstrauss to v1.4.1, it is their last delivery as CJS library. For now seems ok.
An alternative workaround, if you have TS setup, is to patch the ssi-sdk-ext.did-resolver-key delivery that will list "main":"src/index.ts" in the package.json. This will take the TS source code directly and transpile it to ESM.
Solution
Configure tsc to output ESM instead of CJS (or run it two times to output both)
OR, use tsup or esbuild or rollup to create delivery for both CJS and ESM
The text was updated successfully, but these errors were encountered:
Sorry, for not responding earlier. Totally overlooked the issues in this repo and we had no issues in RN because of babel.
Implemented a workaround, as we cannot move to ESM only yet. We will move to both CJS and ESM soon though, so then we can properly fix it. Will keep this ticket open
I have a project that is declared as ESM module (it has
"type":"module"
) inpackage.json
. When I import and try to use@sphereon/ssi-sdk-ext.did-resolver-key
I get the error:This is because the version of
nist-weierstrauss
that is used (v1.6.1), has only ESM builds available. This should be OK, butssi-sdk-ext.did-resolver-key
is distributing only CJS and the import it is making for thenist-weierstrauss
uses therequire
statement. Importing ESM modules withrequire
is not allowed.Minimum reproduction
https://stackblitz.com/edit/stackblitz-starters-6hjrdu
Workaround
As a workaround for my case I have downgraded the nist-weierstrauss to v1.4.1, it is their last delivery as CJS library. For now seems ok.
An alternative workaround, if you have TS setup, is to patch the
ssi-sdk-ext.did-resolver-key
delivery that will list"main":"src/index.ts"
in thepackage.json
. This will take the TS source code directly and transpile it to ESM.Solution
tsc
to output ESM instead of CJS (or run it two times to output both)tsup
oresbuild
orrollup
to create delivery for both CJS and ESMThe text was updated successfully, but these errors were encountered: