Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,12 @@
return msg;
},
Error);

E('ERR_AMBIGUOUS_MODULE_SYNTAX',

Check failure on line 1137 in lib/internal/errors.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

"ERR_AMBIGUOUS_MODULE_SYNTAX" is not documented in doc/api/errors.md

Check failure on line 1137 in lib/internal/errors.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 0 spaces but found 2
'The module syntax is ambiguous. This file mixes CommonJS (require, module.exports) and ES Module features (import, export, or top-level await). Use either CommonJS or ES Modules consistently in the same file.',

Check failure on line 1138 in lib/internal/errors.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

This line has a length of 213. Maximum allowed is 120
Error);

E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);

Check failure on line 1141 in lib/internal/errors.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Out of ASCIIbetical order - ERR_AMBIGUOUS_MODULE_SYNTAX >= ERR_AMBIGUOUS_ARGUMENT
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable', TypeError);
E('ERR_ASSERTION', '%s', Error);
E('ERR_ASYNC_CALLBACK', '%s must be a function', TypeError);
Expand Down
31 changes: 31 additions & 0 deletions test/es-module/test-ambiguous-module-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');

// Skip if ESM is not supported in this environment
common.skipIfESMUnsupported(__filename);

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- /Users/runner/work/node/node/node/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/Users/runner/work/node/node/node/test/common/index.js:1091:13) at Object.<anonymous> (/Users/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- /home/runner/work/node/node/node/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/home/runner/work/node/node/node/test/common/index.js:1091:13) at Object.<anonymous> (/home/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- /home/runner/work/node/node/node/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/home/runner/work/node/node/node/test/common/index.js:1091:13) at Object.<anonymous> (/home/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stderr --- /Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091:13) at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stderr --- /Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091:13) at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared libraries

--- stderr --- /home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091:13) at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js

Check failure on line 9 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- /home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091 throw new Error(`Using invalid common property: '${prop}'`); ^ Error: Using invalid common property: 'skipIfESMUnsupported' at Object.get (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/common/index.js:1091:13) at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js:9:8) at Module._compile (node:internal/modules/cjs/loader:1760:14) at Object..js (node:internal/modules/cjs/loader:1891:10) at Module.load (node:internal/modules/cjs/loader:1480:32) at Module._load (node:internal/modules/cjs/loader:1299:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:245:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v26.0.0-nightly2025-12-1036e617889c-slim/test/es-module/test-ambiguous-module-syntax.js

// Fixture that mixes CJS + ESM
const entry = fixtures.path('es-modules', 'ambiguous-mixed-syntax.js');

const result = spawnSync(process.execPath, [entry], {
encoding: 'utf8'

Check failure on line 15 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
});

// Node should exit with an error
assert.notStrictEqual(result.status, 0);

// Error code must be present
assert.ok(

Check failure on line 22 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Use assert.match instead
/ERR_AMBIGUOUS_MODULE_SYNTAX/.test(result.stderr),
`stderr did not contain ERR_AMBIGUOUS_MODULE_SYNTAX:\n${result.stderr}`
);

// Your new explanatory message should appear
assert.ok(

Check failure on line 28 in test/es-module/test-ambiguous-module-syntax.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Use assert.match instead
/mixes CommonJS/.test(result.stderr),
`stderr did not contain expected message:\n${result.stderr}`
);
8 changes: 8 additions & 0 deletions test/fixtures/es-modules/ambiguous-mixed-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file intentionally mixes CommonJS and ES Module syntax
// to trigger ERR_AMBIGUOUS_MODULE_SYNTAX.

// CommonJS
const fs = require('fs');

// ES Modules
export const value = 123;
Loading