-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: improve commonjs hint on module not found
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a parent-relative path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`) PR-URL: #31906 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
- Loading branch information
Showing
9 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
import obj from 'some_module/obj'; | ||
|
||
throw new Error('Should have errored'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawn } = require('child_process'); | ||
const { join } = require('path'); | ||
const { fixturesDir } = require('../common/fixtures'); | ||
|
||
spawn( | ||
process.execPath, | ||
[ | ||
join(fixturesDir, 'esm_loader_not_found_cjs_hint_bare.mjs') | ||
], | ||
{ | ||
cwd: fixturesDir, | ||
stdio: 'inherit' | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
internal/modules/run_main.js:* | ||
internalBinding('errors').triggerUncaughtException( | ||
^ | ||
|
||
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*fixtures*node_modules*some_module*obj' imported from *test*fixtures*esm_loader_not_found_cjs_hint_bare.mjs | ||
Did you mean to import some_module/obj.js? | ||
at finalizeResolution (internal/modules/esm/resolve.js:*:*) | ||
at packageResolve (internal/modules/esm/resolve.js:*:*) | ||
at moduleResolve (internal/modules/esm/resolve.js:*:*) | ||
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*) | ||
at Loader.resolve (internal/modules/esm/loader.js:*:*) | ||
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*) | ||
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:*:*) | ||
at link (internal/modules/esm/module_job.js:*:*) { | ||
code: 'ERR_MODULE_NOT_FOUND' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Flags: --experimental-loader ./test/common/fixtures | ||
import '../common/index.mjs'; | ||
console.log('This should not be printed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time | ||
(Use `node --trace-warnings ...` to show where the warning was created) | ||
internal/modules/run_main.js:* | ||
internalBinding('errors').triggerUncaughtException( | ||
^ | ||
|
||
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*common*fixtures' imported from * | ||
Did you mean to import ./test/common/fixtures.js? | ||
at finalizeResolution (internal/modules/esm/resolve.js:*:*) | ||
at moduleResolve (internal/modules/esm/resolve.js:*:*) | ||
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*) | ||
at Loader.resolve (internal/modules/esm/loader.js:*:*) | ||
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*) | ||
at Loader.import (internal/modules/esm/loader.js:*:*) | ||
at internal/process/esm_loader.js:*:* | ||
at Object.initializeLoader (internal/process/esm_loader.js:*:*) | ||
at runMainESM (internal/modules/run_main.js:*:*) | ||
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*) { | ||
code: 'ERR_MODULE_NOT_FOUND' | ||
} |