You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error: Cannot find module 'heapdump'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at node.js:858:16
at Array.forEach (native)
at Function.startup.preloadModules (node.js:857:32)
at startup (node.js:95:17)
at node.js:963:3
My expectation was the module would be resolved the same way as if I were to do:
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 .paths property from the parent which gives us a starting point for searching node_module directories.
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.varparent=newModule('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 foo and require(foo). The former search from the working directory of the process upwards whereas the latter starts from the directory of the requiring module.
Note the slight semantic difference between -r foo and require(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.
Activity
ofrobots commentedon May 26, 2015
I'm investigating.
ofrobots commentedon May 26, 2015
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.ofrobots commentedon May 27, 2015
Here's a potential fix I am evaluating:
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.i5ting commentedon May 27, 2015
the same issue
i5ting commentedon May 27, 2015
i want in cli i can use
require 'xxx'Fishrock123 commentedon May 27, 2015
Right, but that seems to make sense, the requiring "module" in this case is effectively the working directory.
ofrobots commentedon May 27, 2015
@Fishrock123 That's my intuition too. I wanted to point it out to make sure it is not surprising to others.
src: fix module search path for preload modules
Fishrock123 commentedon May 30, 2015
Fixed in 5759722!
src: fix module search path for preload modules
bmeck commentedon Aug 12, 2015
Using
process.cwd()makes using preloaded modules with absolute paths blow up when you are in a ENOENT directory. investigating fixmodule: fix module preloading when cwd is ENOENT
module: fix module preloading when cwd is ENOENT