I'm trying to write some CLI program on node using Babel. I'd seen question How do I use babel in a node CLI program? and there loganfsmyth said:
Ideally you'd precompile before distributing your package.
Okay, now I'm using:
"scripts": {
"transpile": "babel cli.js --out-file cli.es5.js",
"prepublish": "npm run transpile",
}
But, I faced the problem, when Babel adds 'use strict';
line right behind #!/usr/bin/env node
header. For example, if I have cli.js
:
#!/usr/bin/env node
import pkg from './package'
console.log(pkg.version);
I'll get this:
#!/usr/bin/env node'use strict';
var _package = require('./package');
… … …
And this doesn't work. When I try to run it, I always get:
/usr/bin/env: node'use strict';: This file or directory does'nt exist
How can I solved this problem?