standard-things / esm

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

Using esm breaks null coalescing operator #879

Open synzhu opened 4 years ago

synzhu commented 4 years ago

I'm encountering a very strange error when using esm via node -r esm main.js.

When my main.js file contains the following, everything works fine and "foo" is printed:

console.log(null ?? "foo");

However, when I add an import statement:

import http from "http";

console.log(null ?? "foo");

Then I get a syntax error:

Simons-MacBook-Pro-2:tribe-server smnzhu$ node -r esm test.js
/Users/smnzhu/Documents/GitHub/tribe/tribe-server/test.js:3
console.log(null ?? "foo");
                  ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)

What's even weirder is, even when I comment out the import statement, it still throws the same error. Furthermore, when I run these commands in the REPL, there are no issues:

Simons-MacBook-Pro-2:tribe-server smnzhu$ node -r esm
Welcome to Node.js v14.3.0.
Type ".help" for more information.
> import http from "http"
undefined
> console.log(null ?? "foo");
foo
undefined
>
(To exit, press ^C again or ^D or type .exit)
>

Any idea what's going on?

bsian03 commented 4 years ago

See #866

jsg2021 commented 4 years ago

It just needs an updated acorn build.

CITguy commented 2 years ago

Have there been any updates to this? Any idea when this might be fixed?

jsg2021 commented 2 years ago

nope. I'd consider it likely dead.