GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — v5.2.0: `require` doesn't work in REPL · Issue #4208 · nodejs/node

v5.2.0: require doesn't work in REPL #4208

New issue
Copy link
New issue
Copy link
Closed
Closed
v5.2.0: require doesn't work in REPL#4208
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.moduleIssues and PRs related to the module subsystem.replIssues and PRs related to the REPL subsystem.

Description

@shinnn
shinnn
opened on Dec 9, 2015
Issue body actions

Environment

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.1
BuildVersion:   15B42

$ node --version
v5.2.0

$ npm --version
3.3.12

$ pwd
/Users/shinnn/test

$ npm ls underscore
test@ /Users/shinnn/test
└── [email protected]

Problem

When I try to require locally installed "underscore" module, Node throws the following error.

$ node --version
v5.2.0
$ node
> require('underscore')
Error: Cannot find module 'underscore'
    at Function.Module._resolveFilename (module.js:327:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:355:17)
    at require (internal/module.js:13:17)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:281:14)
    at REPLServer.runBound [as eval] (domain.js:294:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:83:20)

With Node v5.1.1 it works fine.

$ node --version
v5.1.1
$ node
> require('underscore')
{ [Function]
  _: [Circular],
  VERSION: '1.8.3',
  [...] }

Also, when I directly specify the script path instead of the simple package name underscore, it can load the module as expected.

$ node --version
v5.2.0
$ node
> require('./node_modules/underscore/underscore.js')
{ [Function]
  _: [Circular],
  VERSION: '1.8.3',
  [...] }

Activity

  1. ChALkeR
    added
    moduleIssues and PRs related to the module subsystem.
    replIssues and PRs related to the REPL subsystem.
    on Dec 9, 2015
  2. ChALkeR commented on Dec 9, 2015

    @ChALkeR
    ChALkeR
    on Dec 9, 2015
    Member
    More actions

    Reproduced.

  3. ChALkeR commented on Dec 9, 2015

    @ChALkeR
    ChALkeR
    on Dec 9, 2015
    Member
    More actions

    /cc @bnoordhuis and @cjihrig for ee72ee7, though I didn't bisect and I am not sure which commit broke that.

  4. silverwind
    added
    confirmed-bugIssues and PRs for confirmed bugs.
    on Dec 9, 2015
  5. silverwind commented on Dec 9, 2015

    @silverwind
    silverwind
    on Dec 9, 2015
    Contributor
    More actions

    Also confirmed here. I wonder how that got through our tests.

  6. MylesBorins commented on Dec 9, 2015

    @MylesBorins
    MylesBorins
    on Dec 9, 2015
    Contributor
    More actions

    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

  7. MylesBorins commented on Dec 9, 2015

    @MylesBorins
    MylesBorins
    on Dec 9, 2015
    Contributor
    More actions

    edit: ignore original comment, test was throwing but it appears I didn't wire it up correctly

  8. silverwind commented on Dec 9, 2015

    @silverwind
    silverwind
    on Dec 9, 2015
    Contributor
    More actions

    bisect confirms it's ee72ee7.

  9. bnoordhuis commented on Dec 9, 2015

    @bnoordhuis
    bnoordhuis
    on Dec 9, 2015
    Member
    More actions

    Found the cause, the REPL's module object is missing the .paths property. Diff to illustrate what I mean:

    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.

  10. silverwind commented on Dec 9, 2015

    @silverwind
    silverwind
    on Dec 9, 2015
    Contributor
    More actions

    @bnoordhuis looking good, but I see a unnecessary lookup path repl/node_modules. Maybe it should be parentModule.paths.slice(1) to slice that off the lookup path array?

    $ pwd
    /Users/silverwind/git/test
    $ NODE_DEBUG=module ../iojs/node
    > require("underscore")
    MODULE 1402: Module._load REQUEST underscore parent: <repl>
    MODULE 1402: looking for "underscore" in ["/Users/silverwind/git/test/repl/node_modules","/Users/silverwind/git/test/node_modules","/Users/silverwind/git/node_modules","/Users/silverwind/node_modules","/Users/node_modules","/node_modules","/Users/silverwind/.node_modules","/Users/silverwind/.node_libraries","/Users/silverwind/git/iojs/out/lib/node"]
    MODULE 1402: load "/Users/silverwind/git/test/node_modules/underscore/underscore.js" for module "/Users/silverwind/git/test/node_modules/underscore/underscore.js"
    
  11. bnoordhuis commented on Dec 9, 2015

    @bnoordhuis
    bnoordhuis
    on Dec 9, 2015
    Member
    More actions

    #4215 - using Module._resolveLookupPaths().

  12. bnoordhuis
    added a commit that references this issue on Dec 9, 2015

    repl: fix require('3rdparty') regression

    213ede6
  13. bnoordhuis
    closed this as completedin #4215on Dec 9, 2015
  14. bnoordhuis
    added a commit that references this issue on Dec 15, 2015

    repl: fix require('3rdparty') regression

    1999fdc
  15. shinnn commented on Dec 18, 2015

    @shinnn
    shinnn
    on Dec 18, 2015
    ContributorAuthor
    More actions

    Thanks for the fix and new release!

  16. silverwind commented on Dec 18, 2015

    @silverwind
    silverwind
    on Dec 18, 2015
    Contributor
    More actions

    @shinnn we have to thank you for the quick report!

  17. cjihrig
    added a commit that references this issue on Jan 7, 2016

    repl: fix require('3rdparty') regression

    82c9778
  18. MylesBorins
    added a commit that references this issue on Jan 19, 2016

    repl: fix require('3rdparty') regression

    41882e4
  19. scovetta
    added a commit that references this issue on Apr 2, 2016

    repl: fix require('3rdparty') regression

    17d505d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.moduleIssues and PRs related to the module subsystem.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.