es6-transpiler icon indicating copy to clipboard operation
es6-transpiler copied to clipboard

Error on Hash-Bang

Open kobezzza opened this issue 10 years ago • 5 comments

#!/bin/bash
function foo() {
}

Error:

Error: Line 1: Unexpected token ILLEGAL

kobezzza avatar Sep 11 '14 10:09 kobezzza

Scripts starting with shebang should be invoked directly from shell, not through node.js. You are getting an error because /bin/bash is not a valid interpreter for JavaScript. Try something like #!/usr/bin/env node and look for details about using shebang in general and especially for node.

raiden-dev avatar Sep 11 '14 12:09 raiden-dev

Scripts starting with shebang should be invoked directly from shell, not through node.js.

Yes, but here is something else: the code is not transpiled - es6-transpiler error.

console.es6

#!/usr/bin/env node

/* my console app */

https://github.com/visionmedia/jade/blob/master/bin/jade.js

kobezzza avatar Sep 11 '14 12:09 kobezzza

Why it should be transpiled? It is not a valid JS at all. Transpiler gives a proper error, cause you can not do tricks like this. Transpile your script first and then use transpiled output to make a shell script with a shebang.

raiden-dev avatar Sep 11 '14 13:09 raiden-dev

This could be done optionally, for example

//#!/usr/bin/env node

/* my CLI app */
es6-transpiler myApp.es6 --sha-bang > myApp.js

->

#!/usr/bin/env node

/* my CLI app */

Why not? It is more convenient than writing wrapper.

kobezzza avatar Sep 11 '14 13:09 kobezzza

Such things have no relation to JavaScript. You not blames browsers that throws an exception for invalid code and you can't blame transpiler for the same reasons. You should write the wrapper cause it is out of transpiler's responsibility zone.

raiden-dev avatar Sep 11 '14 13:09 raiden-dev