Closed
Description
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