resolve.sync doesn't respect NODE_PATH
See original GitHub issueThere is an inconsistency in how resolve.sync
and require.resolve
resolve paths:
$ NODE_PATH=/opt/grunt-0.4.2/lib/node_modules node
> require.resolve('grunt')
'/opt/grunt-0.4.2/lib/node_modules/grunt/lib/grunt.js'
> require('resolve').sync('grunt')
Error: Cannot find module 'grunt' from '.'
at Function.module.exports [as sync] (/home/shlevy/test/node_modules/resolve/lib/sync.js:32:11)
at repl:1:21
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
>
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
What's the difference between path.resolve and path.join?
The path.join and path.resolve are two different methods of the path module. Both these methods accept a sequence of paths or path segments....
Read more >Synchronization of PreferenceChangeListener with preference ...
The JDK documentation makes it clear that a call to the put methods may be asynchronous with respect to the write to the...
Read more >Siemens S7 Plus Ethernet Driver - Kepware
The host name provided is invalid and does not resolve to an IP address. Possible Solution: 1. Verify or correct the format of...
Read more >Class NodePath - Rebex.NET
Returns an element of this path. ParentPath. Gets the parent path, or Empty path if this path does not have parent. PathParts. Gets...
Read more >Log Sync Interval - NI - National Instruments
Specifies or returns the mean sync interval used by the 1588 clock. Use a smaller sync interval to make clocks respond more quickly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alright, makes sense. I guess I read the “implements the node
require.resolve()
algorithm” a little too literally.https://github.com/substack/node-resolve/pull/47#issuecomment-45657329 seems clear.
@guncha you’ll note that line in the readme links to the official node resolve algorithm, which by design omits all mention of NODE_PATH. If you file an issue on node’s website, and they update that page, it’ll be a much stronger case to add the behavior here.
Using NODE_PATH is a really bad idea; and when node ships ES module support, it won’t have any concept that enables requiring modules in a nonstandard place, so it’s best to wean yourself off it asap.
The proper solution right now is to pass
process.env.NODE_PATH
intoopts.path
if you absolutely need to rely on it for some reason.Per the above comment and the OP, I’ll close this for now.