question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

resolve.sync doesn't respect NODE_PATH

See original GitHub issue

There 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:closed
  • Created 10 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
gunchacommented, Jun 5, 2017

Alright, makes sense. I guess I read the “implements the node require.resolve() algorithm” a little too literally.

1reaction
ljharbcommented, Jun 5, 2017

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 into opts.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found