standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Node 12 latest ES syntax compatibility #803

Closed sulkaharo closed 5 years ago

sulkaharo commented 5 years ago

The JOSE library seems to use a lot of the latest ES syntaxes introduced in Node 12: https://github.com/panva/jose Using the library in a project with Node 12.2.0 and ESM, when loading the library, this error is produced and the application fails to start.

node_modules/@panva/jose/lib/jwe/encrypt.js:77
  [PROCESS_RECIPIENT] (recipient) {
                      ^
SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)

You can easily reproduce this:

mkdir test
cd test
npm create
npm install esm
npm install panva/jose

Paste this to index.js:

const jose = require('@panva/jose')

const {
  JWE,   // JSON Web Encryption (JWE)
  JWK,   // JSON Web Key (JWK)
  JWKS,  // JSON Web Key Set (JWKS)
  JWS,   // JSON Web Signature (JWS)
  JWT,   // JSON Web Token (JWT)
  errors // errors utilized by @panva/jose
} = jose

then run both node index.js and node -r esm index.js and you'll get the error when ESM is used.

dbo commented 5 years ago

I am experiencing similar syntax problems with 3.2.23 (3.2.22 is ok) running on node 10.15, recent syntax errors reported per #804, too:

  [formatSymbol](formatter, context) {
                ^

SyntaxError: Invalid or unexpected token
Skywalker13 commented 5 years ago

Looks same here with Symbol.iterator (works perfectly with previous release 3.2.22)

/private/node_modules/node-fetch/lib/index.js:908
        [Symbol.iterator]() {
                  ^

SyntaxError: Invalid or unexpected token
    at Module._extensions..js (internal/modules/cjs/loader.js:704:10)
    at Object.require.extensions.(anonymous function) (/private/node_modules/babel-register/lib/node.js:152:7)
jdalton commented 5 years ago

Moving to #804.