decentralized-identity / did-jwt

Create and verify DID verifiable JWT's in Javascript
Apache License 2.0
333 stars 71 forks source link

Question: Module parse failed: Unexpected token (1688:17) #213

Closed vollit closed 2 years ago

vollit commented 2 years ago

Versions:

After installing did-jwt-vc, it keeps giving this error after importing. Can someone explain what this means? It looks like he doesn't like the nullish-coalescing-operator.

I could not find an issue that looks like this, except an issue where it is a issue with React scripts, but this doesn't work.

ERROR in ./node_modules/did-jwt/lib/index.module.js 1688:17
Module parse failed: Unexpected token (1688:17)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|               // TODO: should be able to use non base58 keys too
|               return key.type === 'X25519KeyAgreementKey2019' && Boolean(key.publicKeyBase58);
>             })) ?? [];
|             if (!pks.length && !controllerEncrypters.length) throw new Error(`no_suitable_keys: Could not find x25519 key for ${did}`);
|             return pks.map(pk => x25519Encrypter(base58ToBytes(pk.publicKeyBase58), pk.id)).concat(...controllerEncrypters);
mirceanis commented 2 years ago

In case others run into this issue, what was your solution?

zoernert commented 2 years ago

As I reported #215 - It might be interesting what happens if you try to require or import the did-jwt as early as possible in your runtime. Does the error message disappear?

If my assumption at the moment is right, it might be a mixture of timing/memory management of the class/module loader of Node itself. Even if we do not see something like a heap error or a memory dump.

hiaux0 commented 2 years ago

I've encountered this while working with a webpack 4 project. Reason: Webpack4 uses a version of acorn, that does not support ?? (nullish)

What I had to do was either

  1. update to webpack 5 or
  2. specify a version of acorn, that supports ?? https://github.com/OnurGvnc/acorn-with-stage3 (^ note, to resolve this particular issue, you could also resolve to the latest version of acorn)
zoernert commented 2 years ago

I had the same Dev Project in two different folders. Both had the same code. However, the initial npm i (to get the same dependencies from package.json). One copy works - the other not.