GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — module: fix loading from global folders on Windows by richardlau · Pull Request #9283 · nodejs/node

Conversation

@richardlau

@richardlau richardlau commented Oct 25, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

module

Description of change

According to the module documentation:

Additionally, Node.js will search in the following locations:

    1: $HOME/.node_modules
    2: $HOME/.node_libraries
    3: $PREFIX/lib/node

Where $HOME is the user's home directory, and $PREFIX is Node.js's configured node_prefix.

Loading from $PREFIX/lib/node is broken on Windows as the code is calculating $PREFIX/lib/node
relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the
installed Node.js).

e.g. If Node.js is in c:\node, the code is adding c:\lib\node to the lookup path instead of c:\node\lib\node:

C:\node>set NODE_DEBUG=module

C:\node>node nosuchfile
MODULE 12780: looking for "C:\\node\\nosuchfile" in ["C:\\Users\\IBM_ADMIN\\.nod
e_modules","C:\\Users\\IBM_ADMIN\\.node_libraries","C:\\lib\\node"]
module.js:472
    throw err;
    ^

Error: Cannot find module 'C:\node\nosuchfile'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

C:\node>

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gibfahn and sam-github reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot nodejs-github-bot added the module Issues and PRs related to the module subsystem. label Oct 25, 2016
@richardlau
richardlau force-pushed the global_folders branch 4 times, most recently from 380a0b6 to 37e049a Compare October 25, 2016 23:54
@mscdex mscdex added the windows Issues and PRs related to the Windows platform. label Oct 26, 2016
@gibfahn

gibfahn commented Oct 26, 2016

Copy link
Copy Markdown
Member

cc/ @nodejs/platform-windows

I feel like this would be a semver-patch change, as it's fixing the actual behaviour to match the docs.

CI: https://ci.nodejs.org/job/node-test-pull-request/4677/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Oct 26, 2016

Copy link
Copy Markdown
Member

Given past history, we need to be very careful with changes to the module loader logic. @nodejs/ctc ... thoughts on this?
/cc @nodejs/platform-windows

gibfahn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joaocgreis

joaocgreis commented Nov 1, 2016

Copy link
Copy Markdown
Member

There was already some discussion of this in #6434 , but no decision.

What about removing those 3 search locations altogether? As the doc says, "these are mostly for historic reasons", so perhaps it's time to see them gone. NODE_PATH can be used to achieve the same functionality explicitly. Was there any discussion around this in the past?

If not, I would rather see these paths changed to places that actually make sense on Windows (like %APPDATA%). If that change is still too big, this PR at least makes node behave as described in the docs, so I'm +1 here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@richardlau

richardlau commented Nov 2, 2016 •
edited by gibfahn
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

cc @nodejs/testing since this PR also adds a new testcase to cover the documented behaviour.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sam-github

sam-github commented Dec 8, 2016

Copy link
Copy Markdown
Contributor

@joaocgreis Removing them is an even larger change to a system we are trying to not break! I doubt anyone has an appetite for adding new default paths. I don't think adding $PREFIX/lib/node into the default module resolution path would fly as a new feature, but @richardlau isn't proposing that. Its an existing documented feature, we just want it to work. We have a use-case for it, which is why we noticed its broken on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sam-github
sam-github suggested changes Dec 8, 2016
View reviewed changes

@sam-github sam-github left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing Windows behaviour seems so wrong, its hard to imagine any user-code relying on it. I'm +1. And its great to see tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/module.js Outdated

@sam-github sam-github Dec 8, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, on non-Windows we have

$PREFIX/
   bin/node
   lib/

and on Windows we have

$PREFIX\
  node.exe
  lib/

So the previous code was adding a path like c:\Program Files\lib to the default node search path.. which is just flat-out wrong?

I think the code above could benefit from a comment describing what its doing. Particularly if my guess above is wrong!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gibfahn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@richardlau richardlau Dec 9, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, your understanding is correct. I have added some comments to the code to clarify.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@richardlau
richardlau force-pushed the global_folders branch from 37e049a to 33f2cf5 Compare December 9, 2016 19:22
@nodejs-github-bot nodejs-github-bot added lts-watch-v4.x labels Dec 9, 2016
@richardlau
richardlau force-pushed the global_folders branch from 33f2cf5 to d96e6e0 Compare December 9, 2016 19:27
@nodejs-github-bot nodejs-github-bot added lts-watch-v4.x labels Dec 9, 2016
@richardlau

richardlau commented Dec 9, 2016

Copy link
Copy Markdown
Member Author

Rebased and added a comment to the changed code as suggested by @sam-github.

I've also edited the PR description to (hopefully) make it clearer what problem this is trying to address with an example showing the current (incorrect) behavior.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@richardlau
richardlau force-pushed the global_folders branch from d96e6e0 to 53dd46b Compare December 9, 2016 19:37
@nodejs-github-bot nodejs-github-bot added lts-watch-v4.x labels Dec 9, 2016
@richardlau richardlau changed the title module: fix loading from $PREFIX/lib/node on Windows module: fix loading from global folders on Windows Dec 9, 2016
@richardlau
richardlau force-pushed the global_folders branch from 53dd46b to 72e0f9d Compare December 9, 2016 19:43
@nodejs-github-bot nodejs-github-bot added lts-watch-v4.x labels Dec 9, 2016
@targos targos mentioned this pull request Dec 9, 2016
attempt-backport still does not work Edit: now working?! nodejs/github-bot#100
Closed
sam-github
sam-github approved these changes Dec 9, 2016
View reviewed changes
gibfahn
gibfahn approved these changes Dec 9, 2016
View reviewed changes
joaocgreis
joaocgreis approved these changes Dec 15, 2016
View reviewed changes
@MylesBorins MylesBorins removed lts-watch-v4.x labels Apr 17, 2017
@MylesBorins

MylesBorins commented Apr 17, 2017

Copy link
Copy Markdown
Contributor

Cherry-picked to both v4 and v6. I plan to do a maintenance release for v4 including this and a couple other bugs that have been caught

richardlau reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MylesBorins pushed a commit that referenced this pull request Apr 17, 2017
@richardlau @MylesBorins
test: add test for loading from global folders
4791549
Test executes with a copy of the node executable since $PREFIX/lib/node
is relative to the executable location.

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 17, 2017
@richardlau @MylesBorins
module: fix loading from global folders on Windows
8db3cb4
Code was calculating $PREFIX/lib/node relative to process.execPath, but
on Windows process.execPath is $PREFIX\node.exe whereas everywhere else
process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the
installed Node.js).

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
@richardlau @MylesBorins
test: add test for loading from global folders
1dc6b38
Test executes with a copy of the node executable since $PREFIX/lib/node
is relative to the executable location.

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
@richardlau @MylesBorins
module: fix loading from global folders on Windows
ba91c41
Code was calculating $PREFIX/lib/node relative to process.execPath, but
on Windows process.execPath is $PREFIX\node.exe whereas everywhere else
process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the
installed Node.js).

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
@richardlau @MylesBorins
test: add test for loading from global folders
67b6d7d
Test executes with a copy of the node executable since $PREFIX/lib/node
is relative to the executable location.

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
@richardlau @MylesBorins
module: fix loading from global folders on Windows
500d17b
Code was calculating $PREFIX/lib/node relative to process.execPath, but
on Windows process.execPath is $PREFIX\node.exe whereas everywhere else
process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the
installed Node.js).

PR-URL: #9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
This was referenced Apr 19, 2017
v6.10.3 proposal #12498
Merged
v4.8.3 proposal #12499
Merged
MylesBorins added a commit that referenced this pull request May 2, 2017
@MylesBorins
2017-05-02, Version 4.8.3 'Argon' (Maintenance)
788f280
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) #9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) #11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) #11947
   * (Ben Noordhuis) #11898
   * (jBarz) #11776

PR-URL: #12499
MylesBorins added a commit that referenced this pull request May 2, 2017
@MylesBorins
2017-05-02, Version 6.10.3 'Boron' (LTS)
a0bfd4f
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) #9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) #11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) #11947
   * (Ben Noordhuis) #11898
   * (jBarz) #11776

PR-URL: #12497
MylesBorins added a commit that referenced this pull request May 2, 2017
@MylesBorins
2017-05-02, Version 4.8.3 'Argon' (Maintenance)
9802d46
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) #9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) #11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) #11947
   * (Ben Noordhuis) #11898
   * (jBarz) #11776

PR-URL: #12499
MylesBorins added a commit that referenced this pull request May 2, 2017
@MylesBorins
2017-05-02, Version 6.10.3 'Boron' (LTS)
20e27dd
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) #9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) #11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) #11947
   * (Ben Noordhuis) #11898
   * (jBarz) #11776

PR-URL: #12497
imyller added a commit to imyller/meta-nodejs that referenced this pull request May 2, 2017
@imyller
2017-05-02, Version 4.8.3 'Argon' (Maintenance)
9c2a002
    Notable Changes:

    * module:
      - The module loading global fallback to the Node executable's
        directory now works correctly on Windows.
        (Richard Lau) nodejs/node#9283
    * src:
      - fix base64 decoding in rare edgecase
        (Nikolai Vavilov) nodejs/node#11995
    * tls:
      - fix rare segmentation faults when using TLS
       * (Trevor Norris) nodejs/node#11947
       * (Ben Noordhuis) nodejs/node#11898
       * (jBarz) nodejs/node#11776

    PR-URL: nodejs/node#12499

Signed-off-by: Ilkka Myller <[email protected]>
imyller added a commit to imyller/meta-nodejs that referenced this pull request May 2, 2017
@imyller
2017-05-02, Version 6.10.3 'Boron' (LTS)
6c7c224
    Notable Changes:

    * module:
      - The module loading global fallback to the Node executable's
        directory now works correctly on Windows.
        (Richard Lau) nodejs/node#9283
    * src:
      - fix base64 decoding in rare edgecase
        (Nikolai Vavilov) nodejs/node#11995
    * tls:
      - fix rare segmentation faults when using TLS
       * (Trevor Norris) nodejs/node#11947
       * (Ben Noordhuis) nodejs/node#11898
       * (jBarz) nodejs/node#11776

    PR-URL: nodejs/node#12497

Signed-off-by: Ilkka Myller <[email protected]>
imyller added a commit to imyller/meta-nodejs that referenced this pull request May 2, 2017
@imyller
2017-05-02, Version 4.8.3 'Argon' (Maintenance)
27a8c43
    Notable Changes:

    * module:
      - The module loading global fallback to the Node executable's
        directory now works correctly on Windows.
        (Richard Lau) nodejs/node#9283
    * src:
      - fix base64 decoding in rare edgecase
        (Nikolai Vavilov) nodejs/node#11995
    * tls:
      - fix rare segmentation faults when using TLS
       * (Trevor Norris) nodejs/node#11947
       * (Ben Noordhuis) nodejs/node#11898
       * (jBarz) nodejs/node#11776

    PR-URL: nodejs/node#12499

Signed-off-by: Ilkka Myller <[email protected]>
imyller added a commit to imyller/meta-nodejs that referenced this pull request May 2, 2017
@imyller
2017-05-02, Version 6.10.3 'Boron' (LTS)
3d61075
    Notable Changes:

    * module:
      - The module loading global fallback to the Node executable's
        directory now works correctly on Windows.
        (Richard Lau) nodejs/node#9283
    * src:
      - fix base64 decoding in rare edgecase
        (Nikolai Vavilov) nodejs/node#11995
    * tls:
      - fix rare segmentation faults when using TLS
       * (Trevor Norris) nodejs/node#11947
       * (Ben Noordhuis) nodejs/node#11898
       * (jBarz) nodejs/node#11776

    PR-URL: nodejs/node#12497

Signed-off-by: Ilkka Myller <[email protected]>
anchnk pushed a commit to anchnk/node that referenced this pull request May 6, 2017
@MylesBorins Olivier Martin
2017-05-02, Version 4.8.3 'Argon' (Maintenance)
38a7454
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) nodejs#9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) nodejs#11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) nodejs#11947
   * (Ben Noordhuis) nodejs#11898
   * (jBarz) nodejs#11776

PR-URL: nodejs#12499
anchnk pushed a commit to anchnk/node that referenced this pull request May 6, 2017
@MylesBorins Olivier Martin
2017-05-02, Version 6.10.3 'Boron' (LTS)
f25ca7a
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) nodejs#9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) nodejs#11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) nodejs#11947
   * (Ben Noordhuis) nodejs#11898
   * (jBarz) nodejs#11776

PR-URL: nodejs#12497
@richardlau richardlau mentioned this pull request Jul 16, 2017
Module.globalPaths under Windows #6434
Closed
@refack

refack commented Jul 16, 2017

Copy link
Copy Markdown
Contributor

🎉🎉🎉🎉🎉🎉🎉🎉🎉
Ping @tniessen RE: global node_modules

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
@richardlau @andrew749
test: add test for loading from global folders
261cbc9
Test executes with a copy of the node executable since $PREFIX/lib/node
is relative to the executable location.

PR-URL: nodejs/node#9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
@richardlau @andrew749
module: fix loading from global folders on Windows
be5bde0
Code was calculating $PREFIX/lib/node relative to process.execPath, but
on Windows process.execPath is $PREFIX\node.exe whereas everywhere else
process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the
installed Node.js).

PR-URL: nodejs/node#9283
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: João Reis <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
@MylesBorins @andrew749
2017-05-02, Version 6.10.3 'Boron' (LTS)
94b893c
Notable Changes:

* module:
  - The module loading global fallback to the Node executable's
    directory now works correctly on Windows.
    (Richard Lau) nodejs/node#9283
* src:
  - fix base64 decoding in rare edgecase
    (Nikolai Vavilov) nodejs/node#11995
* tls:
  - fix rare segmentation faults when using TLS
   * (Trevor Norris) nodejs/node#11947
   * (Ben Noordhuis) nodejs/node#11898
   * (jBarz) nodejs/node#11776

PR-URL: nodejs/node#12497
@richardlau richardlau mentioned this pull request Aug 18, 2017
Inconsistent default behavior of node and npm for module installing/loading #14904
Closed
@snyk-bot snyk-bot mentioned this pull request Jan 11, 2023
[Snyk] Fix for 1 vulnerabilities adamlaska/node#99
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bnoordhuis bnoordhuis bnoordhuis approved these changes
+3 more reviewers
@gibfahn gibfahn gibfahn approved these changes
@sam-github sam-github sam-github approved these changes
@joaocgreis joaocgreis joaocgreis approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gibfahn gibfahn

Labels

module Issues and PRs related to the module subsystem. notable-change PRs with changes that should be highlighted in changelogs. windows Issues and PRs related to the Windows platform.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@richardlau @gibfahn @jasnell @joaocgreis @sam-github @MylesBorins @refack @bnoordhuis @mscdex @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.