镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

node --check does not support ESM on Node.js 16 #41189

Description

@matthewrobertson

Version

v16.13.1

Platform

x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Create a simple ESM script:

// foo.mjs
export function testFunction(req, res) {
  return 'PASS';
}

Then run:

node --check foo.mjs

How often does it reproduce? Is there a required condition?

100% of the time

What is the expected behavior?

check should allow ESM exports in files that have a .esm extensions or in projects that set "type": "module" in their package.json

What do you see instead?

node --check does respect the .mjs extension:

node --check foo.mjs
(node:2292833) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/usr/local/google/home/mattrobertson/gcf/functions-framework-nodejs/test/data/esm_mjs/foo.mjs:8
export function testFunction(req, res) {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at checkSyntax (node:internal/main/check_syntax:66:3)
    at node:internal/main/check_syntax:39:3

Additional information

When using v14 the file checks fine:

nvm use 14 # => Now using node v14.18.1 (npm v6.14.15)
node --check foo.mjs

Activity

  1. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    on Dec 16, 2021
  2. Ayase-252 commented on Dec 16, 2021

    @Ayase-252
    Member

    It occurs since v16.12.0.

  3. targos commented on Dec 16, 2021

    @targos
    Member
  4. added a commit that references this issue on Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions