不能 运行 es2015 模式下的全局 babel-node

Can't run global babel-node in es2015 mode

所以当我在本地安装这些包时它们可以工作,但是当全局安装时(并在本地删除它们)

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

似乎那个标志没有设置 es2016-node 来查看全局包列表。无论如何都会发生以下错误:

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,

错误信息中有提示:

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

在本地安装预设,并使用 --save 标志将它们作为依赖项保存在 package.json 中:

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

Babel 的明智之举是只在本地查找预设。通过这种方式,您被迫通过在 package.json 中描述其操作所需的必要依赖项来生成可移植的模块,然后由用户通过 npm install.

安装
npm update

为我解决了这个问题。