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

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

Closed
matthewrobertson opened this issue Dec 15, 2021 · 2 comments · Fixed by #41198
Closed

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

matthewrobertson opened this issue Dec 15, 2021 · 2 comments · Fixed by #41198
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@matthewrobertson
Copy link

matthewrobertson commented Dec 15, 2021

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
@Ayase-252 Ayase-252 added the esm Issues and PRs related to the ECMAScript Modules implementation. label Dec 16, 2021
@Ayase-252
Copy link
Member

It occurs since v16.12.0.

@targos
Copy link
Member

targos commented Dec 16, 2021

It occurs since v16.12.0.

Changelog: https://github.com/nodejs/node/releases/tag/v16.12.0

Ayase-252 added a commit to Ayase-252/node that referenced this issue Dec 16, 2021
nodejs-github-bot pushed a commit that referenced this issue Dec 19, 2021
Fixes: #41189

PR-URL: #41198
Refs: #37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
targos pushed a commit that referenced this issue Jan 14, 2022
Fixes: #41189

PR-URL: #41198
Refs: #37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
Fixes: #41189

PR-URL: #41198
Refs: #37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
Fixes: nodejs#41189

PR-URL: nodejs#41198
Refs: nodejs#37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
danielleadams pushed a commit that referenced this issue Feb 1, 2022
Fixes: #41189

PR-URL: #41198
Refs: #37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants