repl issue with auto-loaded core modules #3564

Closed
mscdex opened this Issue Jun 27, 2012 · 5 comments

5 participants

@mscdex

I was able to reproduce this on both Windows and Linux with node v0.8.0:

> http.get
ReferenceError: http is not defined
    at repl:1:2
    at REPLServer.self.eval (repl.js:111:21)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:88:17)
    at Interface._onLine (readline.js:183:10)
    at Interface._line (readline.js:502:8)
    at Interface._ttyWrite (readline.js:720:14)
    at ReadStream.<anonymous> (readline.js:105:12)
    at ReadStream.EventEmitter.emit (events.js:115:20)
    at emitKey (readline.js:1042:12)
> http
[... lists all of the http module properties ...]
> http.get
[Function]

So, without looking at the code, I'm guessing that all of the modules are not actually being loaded on startup, but lazily loaded somehow when you first reference them by only typing their name?

@TooTallNate

I'm guessing that all of the modules are not actually being loaded on startup, but lazily loaded somehow when you first reference them by only typing their name first?

That is how it works, and yes it is a little weird. We should probably change all those to lazy getters in the repl context instead of hard-coding them into the repl module logic.

@isaacs

+1 for lazy getter. It'd be pretty sweet if the repl had a lazy-getter that just did require(name). Loading native modules automatically is great and all, but I often want to do this with semver and other things.

EDIT: This is new behavior. Not in v0.8 :)

@TooTallNate TooTallNate added a commit to TooTallNate/node that referenced this issue Jul 1, 2012
@TooTallNate TooTallNate repl: attempt to require() the command when a ReferenceError occurs
This is a re-implementation of b722771
to be more robust:

 - fixes #3564
 - it's now a regular require() call under the hood, so it works with modules
   in ./node_modules and $NODE_PATH, etc.
 - logic is cleaner and in a more appropriate place in the repl
d3811ab
@seanmonstar

Did that commit land? Would it solve reference errors when doing fs.existsSync(...) right away?

@langpavel

+1 for lazy getters

@isaacs @TooTallNate: If something like ~/.nodereplrc or ~/.nodeconf.json will be introduced, this stuff (like color setup, lazy getters) can go there.

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