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

esm: fix misleading error when import empty package.json #49728

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
}

THROW_ERR_MODULE_NOT_FOUND(isolate,
"Cannot find package '%s' imported from %s",
"Entry point '%s' resolved from '%s' incorrectly",
package_initial_file,
*module_base);
}
Expand Down
6 changes: 3 additions & 3 deletions test/es-module/test-cjs-legacyMainResolve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

Check failure on line 1 in test/es-module/test-cjs-legacyMainResolve.js

View workflow job for this annotation

GitHub Actions / test-linux

--- stdout --- ::debug::starting to run legacyMainResolve ::debug::starting to run should resolve using packageConfig.main ::debug::completed running should resolve using packageConfig.main ::debug::starting to run should resolve using packageJsonUrl ::debug::completed running should resolve using packageJsonUrl ::debug::starting to run should throw when packageJsonUrl is not URL ::debug::completed running should throw when packageJsonUrl is not URL ::debug::starting to run should throw when packageConfigMain is invalid URL ::debug::completed running should throw when packageConfigMain is invalid URL ::debug::starting to run should throw when packageJsonUrl is invalid URL ::debug::completed running should throw when packageJsonUrl is invalid URL ::debug::starting to run should throw when cannot resolve to a file ::error title=should throw when cannot resolve to a file,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=130,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } at TestContext.<anonymous> (/home/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js:130:12) at Test.runInAsyncScope (node:async_hooks:211:14) at Test.run (node:internal/test_runner/test:916:25) at Suite.processPendingSubtests (node:internal/test_runner/test:614:18) at Test.postRun (node:internal/test_runner/test:1027:19) at Test.run (node:internal/test_runner/test:955:12) at async Suite.processPendingSubtests (node:internal/test_runner/test:614:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Error], expected: [Object], operator: 'throws' } } ::debug::starting to run should not crash when cannot resolve to a file that contains special chars ::debug::completed running should not crash when cannot resolve to a file that contains special chars ::debug::starting to run should report main file on error message when not found ::error title=should report main file on error message when not found,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=151,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.node\' resolved from \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND',

Check failure on line 1 in test/es-module/test-cjs-legacyMainResolve.js

View workflow job for this annotation

GitHub Actions / test-macOS (macos-13)

--- stdout --- ::debug::starting to run legacyMainResolve ::debug::starting to run should resolve using packageConfig.main ::debug::completed running should resolve using packageConfig.main ::debug::starting to run should resolve using packageJsonUrl ::debug::completed running should resolve using packageJsonUrl ::debug::starting to run should throw when packageJsonUrl is not URL ::debug::completed running should throw when packageJsonUrl is not URL ::debug::starting to run should throw when packageConfigMain is invalid URL ::debug::completed running should throw when packageConfigMain is invalid URL ::debug::starting to run should throw when packageJsonUrl is invalid URL ::debug::completed running should throw when packageJsonUrl is invalid URL ::debug::starting to run should throw when cannot resolve to a file ::error title=should throw when cannot resolve to a file,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=130,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } at TestContext.<anonymous> (/Users/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js:130:12) at Test.runInAsyncScope (node:async_hooks:211:14) at Test.run (node:internal/test_runner/test:916:25) at Suite.processPendingSubtests (node:internal/test_runner/test:614:18) at Test.postRun (node:internal/test_runner/test:1027:19) at Test.run (node:internal/test_runner/test:955:12) at async Suite.processPendingSubtests (node:internal/test_runner/test:614:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Error], expected: [Object], operator: 'throws' } } ::debug::starting to run should not crash when cannot resolve to a file that contains special chars ::debug::completed running should not crash when cannot resolve to a file that contains special chars ::debug::starting to run should report main file on error message when not found ::error title=should report main file on error message when not found,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=151,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.node\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOU

Check failure on line 1 in test/es-module/test-cjs-legacyMainResolve.js

View workflow job for this annotation

GitHub Actions / test-macOS (macos-14)

--- stdout --- ::debug::starting to run legacyMainResolve ::debug::starting to run should resolve using packageConfig.main ::debug::completed running should resolve using packageConfig.main ::debug::starting to run should resolve using packageJsonUrl ::debug::completed running should resolve using packageJsonUrl ::debug::starting to run should throw when packageJsonUrl is not URL ::debug::completed running should throw when packageJsonUrl is not URL ::debug::starting to run should throw when packageConfigMain is invalid URL ::debug::completed running should throw when packageConfigMain is invalid URL ::debug::starting to run should throw when packageJsonUrl is invalid URL ::debug::completed running should throw when packageJsonUrl is invalid URL ::debug::starting to run should throw when cannot resolve to a file ::error title=should throw when cannot resolve to a file,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=130,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } at TestContext.<anonymous> (/Users/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js:130:12) at Test.runInAsyncScope (node:async_hooks:211:14) at Test.run (node:internal/test_runner/test:916:25) at Suite.processPendingSubtests (node:internal/test_runner/test:614:18) at Test.postRun (node:internal/test_runner/test:1027:19) at Test.run (node:internal/test_runner/test:955:12) at async Suite.processPendingSubtests (node:internal/test_runner/test:614:7) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Error], expected: [Object], operator: 'throws' } } ::debug::starting to run should not crash when cannot resolve to a file that contains special chars ::debug::completed running should not crash when cannot resolve to a file that contains special chars ::debug::starting to run should report main file on error message when not found ::error title=should report main file on error message when not found,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-cjs-legacyMainResolve.js,line=151,col=12::[Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOUND', + message: 'Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/index.node\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/es-modules/legacy-main-resolver/package.json\' incorrectly' - message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/ } ] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected Comparison { code: 'ERR_MODULE_NOT_FOU

// Flags: --expose-internals

Expand Down Expand Up @@ -129,15 +129,15 @@
);
assert.throws(
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
{ message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' },
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
);
});

it('should not crash when cannot resolve to a file that contains special chars', () => {
const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json');
assert.throws(
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
{ message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' },
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
);
});

Expand All @@ -150,7 +150,7 @@
);
assert.throws(
() => legacyMainResolve(packageJsonUrl, { main: './index.node' }, packageJsonUrl),
{ message: /index\.node/, code: 'ERR_MODULE_NOT_FOUND' },
{ message: /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/, code: 'ERR_MODULE_NOT_FOUND' },
);
});

Expand Down
23 changes: 23 additions & 0 deletions test/es-module/test-import-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

Check failure on line 1 in test/es-module/test-import-empty.js

View workflow job for this annotation

GitHub Actions / test-linux

--- stdout --- ::debug::starting to run Import empty module ::debug::starting to run <anonymous> ::error title=<anonymous>,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js,line=18,col=12::Error [ERR_TEST_FAILURE]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at async Promise.all (index 0) { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at TestContext.<anonymous> (/home/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js:18:12) at async Test.run (node:internal/test_runner/test:917:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:1296:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:297:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'node:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Entry point \'/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\

Check failure on line 1 in test/es-module/test-import-empty.js

View workflow job for this annotation

GitHub Actions / test-macOS (macos-13)

--- stdout --- ::debug::starting to run Import empty module ::debug::starting to run <anonymous> ::error title=<anonymous>,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js,line=18,col=12::Error [ERR_TEST_FAILURE]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at async Promise.all (index 0) { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at TestContext.<anonymous> (/Users/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js:18:12) at async Test.run (node:internal/test_runner/test:917:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:1296:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:297:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'node:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/ind

Check failure on line 1 in test/es-module/test-import-empty.js

View workflow job for this annotation

GitHub Actions / test-macOS (macos-14)

--- stdout --- ::debug::starting to run Import empty module ::debug::starting to run <anonymous> ::error title=<anonymous>,file=dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js,line=18,col=12::Error [ERR_TEST_FAILURE]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at async Promise.all (index 0) { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: AssertionError [ERR_ASSERTION]: The input did not match the regular expression /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/. Input: 'node:internal/modules/esm/resolve:204\n' + ' const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n' + ' ^\n' + '\n' + 'Error: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/index.js\' resolved from \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/[eval]\' incorrectly\n' + ' at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n' + ' at packageResolve (node:internal/modules/esm/resolve:778:12)\n' + ' at moduleResolve (node:internal/modules/esm/resolve:854:18)\n' + ' at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' + ' at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:716:12)\n' + ' at #cachedDefaultResolve (node:internal/modules/esm/loader:640:25)\n' + ' at ModuleLoader.resolve (node:internal/modules/esm/loader:623:38)\n' + ' at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:276:38)\n' + ' at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:579:36)\n' + ' at TracingChannel.tracePromise (node:diagnostics_channel:344:14) {\n' + " code: 'ERR_MODULE_NOT_FOUND'\n" + '}\n' + '\n' + 'Node.js v24.0.0-pre\n' at TestContext.<anonymous> (/Users/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-import-empty.js:18:12) at async Test.run (node:internal/test_runner/test:917:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:1296:7) at async startSubtestAfterBootstrap (node:internal/test_runner/harness:297:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'node:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Entry point \'/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/node_modules/empty/ind

const { spawnPromisified } = require('../common');
const fixtures = require('../common/fixtures.js');
const assert = require('node:assert');
const { execPath } = require('node:process');
const { describe, it } = require('node:test');

describe('Import empty module', { concurrency: true }, () => {
it(async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--eval',
'import("empty")',
], {
cwd: fixtures.path(),
});
assert.match(stderr, /Entry point '[\w\S]+' resolved from '[\w\S]+' incorrectly/);
assert.strictEqual(stdout, '');
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
});
});
1 change: 1 addition & 0 deletions test/fixtures/node_modules/empty/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading