Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
daveisfera opened this issue Sep 28, 2020 · 3 comments
Closed

Comments

@daveisfera
Copy link

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
Copy link
Author

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
Copy link

This is probably related to #866.

@daveisfera
Copy link
Author

Yes, this is a duplicate of that issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants