standard-things / esm

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

Nullish coalescing (`??`) causes `SyntaxError` #909

Open bolivier opened 2 years ago

bolivier commented 2 years ago

I'm on Node 16.13.0, and if I run a script with -r esm, I get a syntax error that isn't present when running without it.

Reproduceable example:

This does not run.

// test.js
import { h } from './test2';
console.log(undefined ?? h);

// test2.js
export const h = "hi";

This runs.

// test.js
const { h } = require('./test2');
console.log(undefined ?? h);

// test2.js
module.exports = {
  h: 'hi'
};

The error I see reads

/proj/test.js:2
console.log(undefined ?? h);
                       ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
blakethepatton commented 2 years ago

Can confirm.

nbrdx commented 2 years ago

Also confirming the problem, using the same node version

TLovers commented 2 years ago

Use a `? . 'will also get syntax errors SyntaxError: Invalid or unexpected token

veeramarni commented 1 year ago

I used chakra-ui and when starting the backend server which uses SSR, it fails with this error in Node 16. This need to fixed in esm