npm scripts给commander传参问题

hellorayza
  • 26

一个node脚本,使用babel-node转换es6,使用了commander来从命令行接收参数。

我可以在build(es6转换)后的代码使用脚本,但是从npm scripts脚本中无法执行node代码。

我的npm scripts

"scripts": {
"test": "babel-node index.js ",
"build": "babel index.js -d dist",
...
},

使用yarn test -h 可以执行出help,但是使用yarn test -i D:/file/test.txt 就不行。我把commander参数写进scriptstest脚本也是一样

"test": "babel-node index.js -h",//可以执行
"test": "babel-node index.js -i d:/file/text.txt" //报错

信息

$ babel-node index -i d:/1/2.md
D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:328
throw e;
^

Error: Options {"loose":true} passed to D:\code\learning\xxx\node_modules\babel-preset-env\lib\index.js which does not accept options. (While processing preset: "D:\\code\\learning\\xxx\\node_modules\\babel-preset-env\\lib\\index.js") (While processing preset: "D:\\code\\learning\\xxx\\node_modules\\babel-preset-env\\lib\\index.js")
at D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:314:17
at Array.map (<anonymous>)
at OptionManager.resolvePresets (D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
at OptionManager.mergePresets (D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
at OptionManager.mergeOptions (D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
at OptionManager.init (D:\code\learning\xxx\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at compile (D:\code\learning\xxx\node_modules\babel-register\lib\node.js:103:45)
at loader (D:\code\learning\xxx\node_modules\babel-register\lib\node.js:144:14)
at Object.require.extensions.<computed> [as .js] (D:\code\learning\xxx\node_modules\babel-register\lib\node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:1000:32)
error Command failed with exit code 1.

我看不出是babel-node哪里的问题

回复
阅读 698
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏