Becca
Becca

Reputation: 1580

Compiled with `coffee` stopped working

I'm not sure what I've done, but I can no longer compile CoffeeScript files. I keep getting the following, regardless of which file I'm trying to compile. I've tried reinstalling coffee by running sudo npm remove --global coffeescript and then sudo npm install --global coffeescript. Automatic compilation in Atom using the coffee-compile package still works. How can I resolve this?

user@computer:~/some/path $ coffee -c code.coffee 
/usr/local/lib/node_modules/coffeescript/lib/coffeescript/command.js:23
  ({spawn, exec} = require('child_process'));
   ^

ReferenceError: Invalid left-hand side in assignment
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/coffeescript/bin/coffee:15:5)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

Upvotes: 1

Views: 382

Answers (2)

Geoffrey Booth
Geoffrey Booth

Reputation: 7366

You have CoffeeScript 2+ installed, which requires Node 6 or later; but your Node runtime is < 6. (The error specifically is that the Node runtime chokes on the ({spawn, exec} = destructuring syntax, which Node < 6 doesn’t understand.) Either install CoffeeScript 1.x or Node 6+.

Upvotes: 1

yacpdb
yacpdb

Reputation: 26

Got the same on Ubuntu 16.04.3 LTS, fixed simply by

$ sudo npm remove --global coffeescript
$ sudo apt-get install coffeescript

Upvotes: 0

Related Questions