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

Most upvoted comments

@gcollazo Depending on where your installation of npm installs global modules, node might not load them by default. You can set the NODE_PATH environment variable to the location of your globally installed node_modules directory.

For nvm users, 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_PATH to tell node where to find modules.