repl.js broken in HEAD? #3395

Closed
cathalgarvey opened this Issue Mar 3, 2014 · 19 comments

Projects

None yet
@cathalgarvey

Hi,
I'm running a fairly fresh install of Linux Mint Debian Edition. I've manually compiled node and npm from their respective git repos, and have just D/L'd coffee-script from this git repo. So, everything is as fresh as can be!

I've had some bugs with npm itself, where it was installing outdated required libs and kept complaining when I'd try to use bin/cake that it couldn't find underscore.. telling npm to update fixed that issue, thankfully.

Now, bin/cake is working, but tests fail, and I still have a persistent problem with bin/coffee, though. Running coffee, I get this:

me@localhost ~/locallib/coffee-script $ git pull
Already up-to-date.
me@localhost ~/locallib/coffee-script $ bin/coffee
coffee> /home/cathal/locallib/coffee-script/lib/coffee-script/repl.js:48
      initialPrompt: repl.prompt.replace(/^[^> ]*/, function(x) {
                                 ^
TypeError: Object function (preserveCursor) {
  if (this.paused) this.resume();
  if (this.terminal) {
    if (!preserveCursor) this.cursor = 0;
    this._refreshLine();
  } else {
    this.output.write(this._prompt);
  }
} has no method 'replace'
  at addMultilineHandler (/home/cathal/locallib/coffee-script/lib/coffee-script/repl.js:48:34)
  at Object.module.exports.start (/home/cathal/locallib/coffee-script/lib/coffee-script/repl.js:155:7)
  at Object.exports.run (/home/cathal/locallib/coffee-script/lib/coffee-script/command.js:79:32)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/bin/coffee:7:41)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:349:32)
  at Function.Module._load (module.js:305:12)
  at Function.Module.runMain (module.js:490:10)
  at startup (node.js:124:16)
  at node.js:803:3

Running bin/cake build:all, I get this:

failed 3 and passed 548 tests in 9.97 seconds 

  CoffeeScript.eval can run in, and modify, a Script context sandbox 
  TypeError: Object function ContextifyScript() { [native code] } has no method 'createContext'
  at Function.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:13:25)
  at global.test (/home/cathal/locallib/coffee-script/Cakefile:275:12)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:12:3)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:1:1)
  at Module._compile (module.js:449:26)

  function () {
      var code, result, sandbox;
      sandbox = vm.Script.createContext();
      sandbox.foo = 'bar';
      code = 'global.foo = \'not bar!\'';
      result = CoffeeScript["eval"](code, {
        sandbox: sandbox
      });
      eq(result, 'not bar!');
      return eq(sandbox.foo, 'not bar!');
    }

  CoffeeScript.eval can run in, but cannot modify, an ordinary object sandbox 
  TypeError: Object function ContextifyScript() { [native code] } has no method 'createContext'
  at Object.exports.eval (/home/cathal/locallib/coffee-script/lib/coffee-script/coffee-script.js:133:47)
  at Function.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:27:14)
  at global.test (/home/cathal/locallib/coffee-script/Cakefile:275:12)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:22:3)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/eval.coffee:1:1)
  at Module._compile (module.js:449:26)

  function () {
      var code, result, sandbox;
      sandbox = {
        foo: 'bar'
      };
      code = 'global.foo = \'not bar!\'';
      result = CoffeeScript["eval"](code, {
        sandbox: sandbox
      });
      eq(result, 'not bar!');
      return eq(sandbox.foo, 'bar');
    }

  TypeError: Object function (preserveCursor) {
  if (this.paused) this.resume();
  if (this.terminal) {
    if (!preserveCursor) this.cursor = 0;
    this._refreshLine();
  } else {
    this.output.write(this._prompt);
  }
} has no method 'replace'
  at addMultilineHandler (/home/cathal/locallib/coffee-script/lib/coffee-script/repl.js:48:34)
  at Object.module.exports.start (/home/cathal/locallib/coffee-script/lib/coffee-script/repl.js:155:7)
  at testRepl (/home/cathal/locallib/coffee-script/test/repl.coffee:37:15)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/repl.coffee:43:1)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/repl.coffee:1:1)
  at Module._compile (module.js:449:26)

Any ideas? :-/

edit by @michaelficarra: cleaned up formatting

@michaelficarra
Collaborator

I cannot reproduce. What version of node are you using? What is the result of running require('repl').start({}).prompt in your node REPL?

edit: I see that you mentioned you were using a freshly built node. Please use a release version while we're debugging this.

@cathalgarvey

Gimme a few, I'll try to roll back the node git repo to a tag or "release", re-build and re-try.
If it is a nodejs HEAD problem, still worth looking into before it becomes a break in the next version of node! :)

@cathalgarvey

Moved node back to tag "tags/v0.9.9", rebuilt and reinstalled.
Fixed the coffeescript issues, so it's a problem with node's HEAD; probably worth saying to them! :)
However, the coffeescript build/install process still failed in one respect: "sudo bin/cake install" failed to install coffeescript because it couldn't find "README". cp README.md README fixed that.
Also, one test failed with the following message:

failed 1 and passed 550 tests in 7.26 seconds 

  Error: EACCES, permission denied '.coffee_history_test'
  at Object.fs.openSync (fs.js:392:18)
  at Object.fs.writeFileSync (fs.js:910:15)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/repl.coffee:32:4)
  at Object.<anonymous> (/home/cathal/locallib/coffee-script/test/repl.coffee:1:1)
  at Module._compile (module.js:456:26)

@michaelficarra
Collaborator

Oh yes, that's a very recent change. I'll fix that.

@michaelficarra
Collaborator

@cathalgarvey: Can you try again using a newer tag such as v0.11.11, the newest tag in the 0.11.x series?

@cathalgarvey

Hi Michael,
Updated to 0.11.11 (sorry, "alphabetical" order in git tags meant I didn't see the newer tags!), and all still works. So, it's an issue with nodejs's HEAD commit at the time I pulled; some future change to node that's incompatible with Coffeescript as things stand.

Thanks for your help, sorry for the delay closing!

@michaelficarra
Collaborator

I guess we'll see what happens when 0.11.12 comes out.

@t3chnoboy

REPL doesn't work in 0.11.12.
Here's the output:

coffee> /usr/local/lib/node_modules/coffee-script/lib/coffee-script/repl.js:48
      initialPrompt: repl.prompt.replace(/^[^> ]*/, function(x) {
                                 ^
TypeError: Object function (preserveCursor) {
  if (this.paused) this.resume();
  if (this.terminal) {
    if (!preserveCursor) this.cursor = 0;
    this._refreshLine();
  } else {
    this.output.write(this._prompt);
  }
} has no method 'replace'
  at addMultilineHandler (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/repl.js:48:34)
  at Object.module.exports.start (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/repl.js:155:7)
  at Object.exports.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:79:32)
  at Object.<anonymous> (/usr/local/lib/node_modules/coffee-script/bin/coffee:7:41)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:349:32)
  at Function.Module._load (module.js:305:12)
  at Function.Module.runMain (module.js:490:10)
  at startup (node.js:124:16)
  at node.js:803:3
@t3chnoboy

Looks like this commit broke it.

@ehuss ehuss added a commit to ehuss/coffee-script that referenced this issue Apr 19, 2014
@ehuss ehuss Fix repl for Node 0.11.12.
Node changed their repl so that it inherits from readline.Interface.
This means that `prompt` is now the rli function and not the original
prompt string.  This may be a little hacky, but I figure it would give
someone a start if they want to do a better fix.

The commit that changed this in Node is nodejs/node-v0.x-archive@3ae0b17

This bug was mentioned in Issue #3395.
03705c6
@huyx

I'm not sure it's the better solution, I just change prompt to _prompt in the following lines:

-    initialPrompt: repl.prompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-'
-    prompt: repl.prompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.'
+    initialPrompt: repl._prompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-'
+    prompt: repl._prompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.'
@vincentwoo

Just adding that this problem persists in node v0.11.13 and coffeescript v1.7.1 as well, just in case anyone was curious.

@mck-

fyi, also breaks on 0.11.12, but works when reverting to 0.11.11

@hgupta

Breaks in 0.11.13 too.

@beilharz

Had the same problem in 0.11.13.
npm install -g http://github.com/jashkenas/coffeescript/tarball/master fixes it.

Are there plans for the next npm release?

@mck-

thanks @beilharz ! it has been bothering my quite a bit ;-)

@joehakimrahme

I still have the same problem with node 0.12.0 and coffee 1.7.1 installed with npm.

npm install -g http://github.com/jashkenas/coffeescript/tarball/master didn't fix it.

@ognus

@joehakimrahme I got the same problem after updating to node 0.12.0. Using coffee 1.7.1

@skrat

Same here

@bepetersn

For posterity... Had this same problem just now. Updating coffeescript via @joehakimrahme above did fix it.

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