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

Compiling into a Python virtual environment and the node_modules path is wrong. #17612

Closed
cnobile2012 opened this issue Dec 11, 2017 · 5 comments
Labels
invalid Issues and PRs that are invalid. module Issues and PRs related to the module subsystem.

Comments

@cnobile2012
Copy link

cnobile2012 commented Dec 11, 2017

I'm installing the latest version 9.2.1 as of this writing. though this issue exists at least back to version 8.9.3. After doing the install and running module at the node prompt I see that the path to node_modules is wrong. It's missing _modules after /home/cnobile/.virtualenvs/realm/lib/node. I altered the actual username.

> module
Module {
  id: '<repl>',
  exports: {},
  parent: undefined,
  filename: null,
  loaded: false,
  children: [],
  paths: 
   [ '/home/{username}/src/django/local_realm/repl/node_modules',
     '/home/{username}/src/django/local_realm/node_modules',
     '/home/{username}/src/django/node_modules',
     '/home/{username}/src/node_modules',
     '/home/{username}/node_modules',
     '/home/node_modules',
     '/node_modules',
     '/home/{username}/.node_modules',
     '/home/{username}/.node_libraries',
     '/home/{username}/.virtualenvs/realm/lib/node' ] }
  • Version: 9.2.1
  • Platform: Linux eggwarmer 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: ?
@bnoordhuis
Copy link
Member

I'm installing the latest version 9.2.1

How are you installing it? Where does the binary come from?

@cnobile2012
Copy link
Author

/home/{username}/.virtualenvs/realm/bin/node is the binary and it is found with no problem. The issue is when I use require nothing is found. For example, if I run the test below.

var test = require('tape');

test('timing test', function (t) {
  t.plan(2);

  t.equal(typeof Date.now, 'function');
  var start = Date.now();

  setTimeout(function () {
    t.equal(Date.now() - start, 100);
  }, 100);
});

I get this result.

module.js:544
    throw err;
    ^

Error: Cannot find module 'tape'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/cnobile/src/django/local_realm/realm/tests/tape-tests.js:1:74)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

If I set NODE_PATH to node_modules/ in the VE it works correctly. However, I consider this a workaround for the fact that when installing node it sets the path ending with node/ instead of node_modules. There is no directory named lib/node/

@richardlau
Copy link
Member

This is working as documented -- Note that lib/node is a legacy global path: https://nodejs.org/dist/latest-v9.x/docs/api/modules.html#modules_loading_from_the_global_folders.

By design Node.js does not look in $PREFIX/lib/node_modules by default when searching for required modules.

@cnobile2012
Copy link
Author

I've been building packages for over 30 years. I have never seen a package that doesn't know where its own resources are. I consider this bad design if this is the way it's documented. The docs say that with the new way node finds packages it lessons the need for the environment variable NODE_PATH, but from what I see it means that everybody will need to use NODE_PATH just to find node's resources. IMHO this is a designed in bug that drives a lot of people crazy when using node.

Just google "node cannot find module" and see how many people have this issue.

@bnoordhuis bnoordhuis added invalid Issues and PRs that are invalid. module Issues and PRs related to the module subsystem. labels Dec 11, 2017
@bnoordhuis
Copy link
Member

I'm going to close this out because it's working as expected (as has been explained) and it's not something we'll change lightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants