2

so when I install these packages locally they work, but when installed globally (and removed them locally)

 npm i babel-cli -g
 npm i -g babel-preset-es2015
 npm i -g babel-preset-es2015-node

seems like that flag isn't setting es2016-node to look in the global package list. anyways this following error occurs:

npm run start myfile.js

babel-node --presets es2015-node -- bin/myScript.js "myfile.js"

/usr/local/Cellar/node/6.1.0/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:395
          throw new Error("Couldn't find preset " + (0, _stringify2.default)(val) + " relative to directory " + (0, _stringify2.default)(dirname));
          ^

Error: Couldn't find preset "es2015-node" relative to directory "/Users/user/project/bin"
    at /usr/local/Cellar/node/6.1.0/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:395:17
    at Array.map (native)
    at OptionManager.resolvePresets (/usr/local/Cellar/node/6.1.0/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:387:20)
    at OptionManager.mergePresets (/usr/local/Cellar/node/6.1.0/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:370:10)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/6.1.0/bin/node" "/usr/local/bin/npm" "run" "start" "myfile.js"
npm ERR! node v6.1.0
npm ERR! npm  v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! project@0.0.0 start: `babel-node --presets es2015-node -- bin/myScript.js "myfile.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.0.0 start script 'babel-node --presets es2015-node -- bin/myScript.js "myfile.js"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the project package,
user2167582
  • 5,986
  • 13
  • 64
  • 121

2 Answers2

2

A hint is in the error message:

Couldn't find preset "es2015-node" relative to directory "/Users/user/project/bin"

Install the presets locally and have them saved as dependencies in your package.json by using the --save flag:

npm install --save babel-preset-es2015-node babel-preset-es2015

It is a wise move by Babel that presets are looked for locally only. This way you are forced to produce a module that is portable by describing the necessary dependencies required for its operation within the package.json, which are then installed by users via npm install.

sdgluck
  • 24,894
  • 8
  • 75
  • 90
  • 1
    wouldn't it be wiser to build the es2015 within the babel-node, so people can use flag to fast configure it instead of dealing with a global executable looking for dirpath modules/configs? – user2167582 Jun 28 '16 at 18:18
  • Babel isn't exclusively an ES6 -> ES5 transpiler, hence the configuration necessary for it to do this. – sdgluck Jun 28 '16 at 18:20
  • maybe not, but i feel that babel-node without es2015 is inadaquete as a node runner as it doesn't understand module pattern, destructuring and perhaps other important features, why not have babel-node as a separate package that include babel-node-es2015. – user2167582 Jun 28 '16 at 20:27
0
npm update

solved the issue for me.

Pang
  • 9,564
  • 146
  • 81
  • 122
user732456
  • 2,638
  • 2
  • 35
  • 49