Repository navigation
-r/--require flag for npm modules #1803
Description
Activity
I'm investigating.
The problem is related to the fact that preload modules do not have a parent. Not even the main module. As such they don't use the
.pathsproperty from the parent which gives us a starting point for searchingnode_moduledirectories.Here's a potential fix I am evaluating:
Module.preloadModules = function(requests) { if (requests) { // Preloaded modules have a dummy parent module which is deemed to exist // in the current working directory. This seeds the search path for // preloaded modules. var parent = new Module('internal/preload', null); parent.paths = Module._nodeModulePaths(process.cwd()); requests.forEach(function(request) { Module._load(request, parent, false); }); } }
Note the slight semantic difference between
-r fooandrequire(foo). The former search from the working directory of the process upwards whereas the latter starts from the directory of the requiring module.- addedmoduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
on May 27, 2015 the same issue
i want in cli i can use
require 'xxx'Note the slight semantic difference between
-r fooandrequire(foo). The former search from the working directory of the process upwards whereas the latter starts from the directory of the requiring module.Right, but that seems to make sense, the requiring "module" in this case is effectively the working directory.
Reacted by Siyuan Ling@Fishrock123 That's my intuition too. I wanted to point it out to make sure it is not surprising to others.
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on May 30, 2015 - added a commit that references this issue
on May 30, 2015 Fixed in 5759722!
- added a commit that references this issue
on Jun 3, 2015 Using
process.cwd()makes using preloaded modules with absolute paths blow up when you are in a ENOENT directory. investigating fix- added 2 commits that reference this issue
on Aug 24, 2015
Given the following steps:
I get the following error:
My expectation was the module would be resolved the same way as if I were to do: