Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Using esm breaks null coalescing operator #879

@synzhu

Description

@synzhu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions