我已经执行了以下行,它编译得很好:
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",
答案 0 :(得分:2)
@_jayphelps见this tweet:
如果你遇到错误,那就像""""或" Logger.error"或类似,升级babel核心! https://github.com/babel/babel/pull/3635
因此,请尝试升级babel-core
和其他Babel模块。您可以使用此命令执行此操作:
npm i -D babel-core@latest
i
是install
的快捷方式,-D
将包添加到devDependencies
中的package.json
(它与{{1}相同}}),--save-dev
安装最新版本。
答案 1 :(得分:2)
事实证明我使用的是全球安装的babel-cli
,而不是使用本地安装的(最新的)。
一旦我像这样运行它,一切顺利:
node_modules/babel-cli/bin/babel.js src --out-dir lib --presets react,latest
感谢所有帮助过的人。