-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Closed
Closed
Copy link
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
- Version: v12.1.0
- Platform: Darwin mba4.local 18.5.0 Darwin Kernel Version 18.5.0
- Subsystem: Modules
I have a module lib/something.js
which looks like this:
module.exports = function something () {}
In the node v10 REPL, this require.resolve
invocation works fine:
> require.resolve('lib/something.js', { paths: [ '.' ] })
'/Users/lloyd/Documents/75lb/load-module/lib/something.js'
In node v12, it no longer works.
> require.resolve('lib/something.js', { paths: [ '.' ] })
Thrown:
Error: Cannot find module 'lib/something.js'
Require stack:
- /Users/lloyd/Documents/75lb/load-module/[eval]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.resolve (internal/modules/cjs/helpers.js:21:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/lloyd/Documents/75lb/load-module/[eval]' ]
}
In node v12, you need to prepend ./
to the module ID like this:
> require.resolve('./lib/something.js', { paths: [ '.' ] })
'/Users/lloyd/Documents/75lb/load-module/lib/something.js'
This is an issue for my users because the path passed to require.resolve
comes from command-line input, e.g.
$ example lib/something.js
Is this the expected new behaviour of require.resolve
or a bug? Do I need to update my tools to prepend ./
?
Metadata
Metadata
Assignees
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.