Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require.resolve.paths truncated #28215

Closed
paul-marechal opened this issue Jun 13, 2019 · 3 comments
Closed

require.resolve.paths truncated #28215

paul-marechal opened this issue Jun 13, 2019 · 3 comments

Comments

@paul-marechal
Copy link

paul-marechal commented Jun 13, 2019

  • Version: 10.2.1
  • Platform: Ubuntu 16.04

This can be observed in the logs from the following error: #18230

I have the same behavior: Some paths that should end with node_modules end with just node. After looking at the parent folder, I can indeed see a node_module folder, but not node.

To me this looks like truncated paths, but not entirely sure.

> require.resolve.paths('why-is-node-running')
[ '/home/paul/repl/node_modules',
  '/home/paul/node_modules',
  '/home/node_modules',
  '/node_modules',
  '/home/paul/.node_modules',
  '/home/paul/.node_libraries',
  '/home/paul/.nvm/versions/node/v10.2.1/lib/node',
  '/home/paul/.node_modules',
  '/home/paul/.node_libraries',
  '/home/paul/.nvm/versions/node/v10.2.1/lib/node' ]

Say in /home/paul/.nvm/versions/node/v10.2.1/lib/: there is only a node_modules folder.

For some reason some paths are also repeated, but the truncated paths concern me more.

An effect this issue has is that I can see the module I am looking for (why-is-node-running) inside /home/paul/.nvm/versions/node/v10.2.1/lib/node_modules, but since node doesn't look in the right place, I cannot require it.

@richardlau
Copy link
Member

They're not truncated -- they're historical: https://nodejs.org/dist/latest-v10.x/docs/api/modules.html#modules_loading_from_the_global_folders
(As far as I know no package manager will actually allow you to install things into those folders.)

Not sure why they are repeated though.

@paul-marechal
Copy link
Author

@richardlau thank you for the link, did not see that before.

Although, repetition aside, why does npm install the global packages right next to it, while node doesn't look it up? Is that to avoid global packages conflicting with actual dependencies? I was expecting to be able to import a global package, am I in the wrong?

@paul-marechal
Copy link
Author

paul-marechal commented Jun 13, 2019

Apparently I am in the wrong: https://stackoverflow.com/a/15646750/7983255

Was following the instructions from why-is-node-running saying we could simply install globally and use it after, but I'll simply have to point this NODE_PATH variable to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants