babel: npm-running a babel-node script doesn’t work
File my_repo/foo.js:
#!/usr/bin/env babel-node
import * as fs from 'fs';
...
File my_repo/package.json:
...
"bin": {
"foo": "./foo.js"
},
...
./foo.js works nicely, but if I do npm run foo, I get:
/Users/rauschma/my_repo/foo.js:3
import * as fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word
Any ideas on how to fix this? Thanks!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- fix babel-node in npm scripts fix #2703 — committed to iamstarkov/babel by iamstarkov 9 years ago
@gcollazo Depending on where your installation of
npminstalls global modules,nodemight not load them by default. You can set theNODE_PATHenvironment variable to the location of your globally installednode_modulesdirectory.For
nvmusers, it seems that"$(npm config get prefix)/lib/node_modules"is the path to the current globally installed modules directory. (May not work for all configurations).The global installation (and use) of presets is possible (at least from my testing) when using
NODE_PATHto tell node where to find modules.