我已经执行了以下行,它编译得很好:
babel src --out-dir lib --presets react,es2015
但是,当我将es2015改为latest并运行它时:
babel src --out-dir lib --presets react,latest
我得到以下错误:
TypeError: [BABEL] src/MyComponent.js: Invalid options type for /Users/liadrian/Dev/react-reveal-text/node_modules/babel-preset-latest/lib/index.js
at Logger.error (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/logger.js:39:11)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:243:16)
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:349:14
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:24
at Array.map (native)
at OptionManager.resolvePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:364:20)
at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:348:10)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:307:14)
at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:465:10)
at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:194:75)我觉得这很奇怪,因为我确保安装了latest预置,node_modules/babel-preset-latest/目录的存在就是证明。
否则一切都会很好。latest预置是什么导致它绊倒的?我已经尝试了以下所有预置,它们工作得很好:es2015、es2016、es2017。只是latest预置把一切都绊倒了。
任何有关故障排除的帮助都将不胜感激。
编辑:我的包版本
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",发布于 2016-12-25 22:55:21
结果发现,我使用的是全局安装的babel-cli,而不是本地安装的(这是最新的)。
当我像这样运行时,一切都很顺利:
node_modules/babel-cli/bin/babel.js src --out-dir lib --presets react,latest
感谢所有帮助我的人。
发布于 2016-12-25 22:36:27
参见这条推特 by @_jayphelps:
如果您遇到错误w/ babel,如“无效选项类型”或"Logger.error“或类似错误,请升级babel-core!https://github.com/babel/babel/pull/3635。
因此,尝试升级babel-core和其他Babel模块。您可以使用以下命令来完成这一任务:
npm i -D babel-core@latesti是install的快捷方式,-D在package.json中将包添加到devDependencies (与--save-dev相同),@latest安装可用的最新版本。
https://stackoverflow.com/questions/41324910
复制相似问题