standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

esm causes optional chaining to be viewed as invalid syntax in node 14 #891

Closed daveisfera closed 4 years ago

daveisfera commented 4 years ago

Use of esm causes optional chaining to be viewed as invalid syntax. Here's an example:

import get from 'lodash/fp/get';

const a = { a: { b: 5 } };

console.log(get(['a', 'b'], a));
console.log(a?.a?.b);
console.log(get(['a', 'c'], a));
console.log(a?.a?.c);

Running node --experimental-specifier-resolution=node test.js outputs the following:

5
5
undefined
undefined

But running node -r esm test.js outputs this error:

/Users/dlj/projects/esm_test/test.js:6
console.log(a?.a?.b);
              ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
daveisfera commented 4 years ago

Probably also worth pointing out that we're looking into switching to using the ESM support in node 14, but we're currently blocked by this issue

CleyFaye commented 4 years ago

This is probably related to #866.

daveisfera commented 4 years ago

Yes, this is a duplicate of that issue