-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
v5.2.0: require
doesn't work in REPL
#4208
Comments
Reproduced. |
/cc @bnoordhuis and @cjihrig for ee72ee7, though I didn't bisect and I am not sure which commit broke that. |
Also confirmed here. I wonder how that got through our tests. |
Doesn't appear to be a test that checks the repl loading a module atm.. trying to put together a test right now to make the bisect easier |
edit: ignore original comment, test was throwing but it appears I didn't wire it up correctly |
bisect confirms it's ee72ee7. |
Found the cause, the REPL's diff --git a/lib/repl.js b/lib/repl.js
index 989e2e9..4d117e5 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -35,6 +35,7 @@ const Module = require('module');
const domain = require('domain');
const debug = util.debuglog('repl');
+const parentModule = module;
const replMap = new WeakMap();
try {
@@ -525,7 +526,8 @@ REPLServer.prototype.createContext = function() {
context.global.global = context;
}
- const module = new Module('<repl>');
+ const module = new Module('<repl>', parentModule);
+ module.paths = parentModule.paths.slice(0);
const require = internalModule.makeRequireFunction.call(module);
context.module = module;
context.require = require; I'll put together a proper fix. |
@bnoordhuis looking good, but I see a unnecessary lookup path
|
#4215 - using |
Fix module loading of third-party modules in the REPL by inheriting module.paths from the REPL's parent module. Commit ee72ee7 ("module,repl: remove repl require() hack") introduced a regression where require() of modules in node_modules directories no longer worked in the REPL (and fortunately only in the REPL.) It turns out we didn't have test coverage for that but we do now. Fixes: nodejs#4208 PR-URL: nodejs#4215 Reviewed-By: Roman Reiss <me@silverwind.io>
Fix module loading of third-party modules in the REPL by inheriting module.paths from the REPL's parent module. Commit ee72ee7 ("module,repl: remove repl require() hack") introduced a regression where require() of modules in node_modules directories no longer worked in the REPL (and fortunately only in the REPL.) It turns out we didn't have test coverage for that but we do now. Fixes: #4208 PR-URL: #4215 Reviewed-By: Roman Reiss <me@silverwind.io>
Thanks for the fix and new release! |
@shinnn we have to thank you for the quick report! |
Fix module loading of third-party modules in the REPL by inheriting module.paths from the REPL's parent module. Commit ee72ee7 ("module,repl: remove repl require() hack") introduced a regression where require() of modules in node_modules directories no longer worked in the REPL (and fortunately only in the REPL.) It turns out we didn't have test coverage for that but we do now. Fixes: nodejs#4208 PR-URL: nodejs#4215 Reviewed-By: Roman Reiss <me@silverwind.io>
Fix module loading of third-party modules in the REPL by inheriting module.paths from the REPL's parent module. Commit ee72ee7 ("module,repl: remove repl require() hack") introduced a regression where require() of modules in node_modules directories no longer worked in the REPL (and fortunately only in the REPL.) It turns out we didn't have test coverage for that but we do now. Fixes: #4208 PR-URL: #4215 Reviewed-By: Roman Reiss <me@silverwind.io>
Fix module loading of third-party modules in the REPL by inheriting module.paths from the REPL's parent module. Commit ee72ee7 ("module,repl: remove repl require() hack") introduced a regression where require() of modules in node_modules directories no longer worked in the REPL (and fortunately only in the REPL.) It turns out we didn't have test coverage for that but we do now. Fixes: nodejs#4208 PR-URL: nodejs#4215 Reviewed-By: Roman Reiss <me@silverwind.io>
Environment
Problem
When I try to
require
locally installed "underscore" module, Node throws the following error.With Node v5.1.1 it works fine.
Also, when I directly specify the script path instead of the simple package name
underscore
, it can load the module as expected.The text was updated successfully, but these errors were encountered: