Unexpected Coffeescript ILLEGAL token, but there should be nothing illegal

It really pisses me off. I cannot find anywhere in my code where I am doing something illegal, but for some reason, calling fork explodes my program. Here is the code. The corresponding part is in svgToPNG where I call fork .

 {fork} = require 'child_process' {Coral} = require 'coral' svgToPNG = (svg, reply, log) -> log "converting SVG to a PNG" # set up a child process to call convert svg: png:- convert = fork '/usr/bin/env', ['convert', 'svg:', 'png:-'] log "Spawned child process running convert, pid " + convert.pid # set up behavior when an error occurs convert.stderr.on "data", -> log "Error occurred while executing convert" reply "error" # set up behavior for when we successfully convert convert.stdout.on "data", -> log "Successful conversion! :)" log "here the data: " + data reply data # pipe the SVG into the stdin of the process (starting it) convert.stdin.end svg 

If I select the fork line and replace it with something else, everything will be shitty, but if I leave it I get:

 > coffee src/coral_client.coffee finished doing conversion to svg! converting SVG to a PNG Spawned child process running convert, pid 60823 /usr/bin/grep:1 (function (exports, require, module, __filename, __dirname) {      ^ SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3 

That doesn't make any sense. I don’t have any strange illegal Unicode character, as in this question , I don’t believe that I have any kind of parsing error, for example, in this I really don’t know what is happening.

Could CoffeeScript somehow violate the code? It seems unlikely, but I do not know.

+7
javascript coffeescript
source share
1 answer

Error using fork . fork intended for spawning Node processes, i.e. foo.js files. Use spawn instead.

I figured this out by running the cut version of your code, reading the image file, and then transferring it to your svgToPNG . An error message will appear:

 /usr/bin/env:1 (function (exports, require, module, __filename, __dirname) { ELF 

The characters displayed in this copy / paste as ELF are the main characters of my binary /usr/bin/env . So node.js fork trying to compile the file /usr/bin/env . This is confirmed by the child_process documentation. For examples that do things like ls and grep , use spawn .

+2
source share

All Articles