[英]babel-cli not working with latest preset
I've executed the following line, and it compiles fine: 我执行了以下行,它编译得很好:
babel src --out-dir lib --presets react,es2015
But when I change es2015
to latest
, and run it: 但是当我将
es2015
更改为latest
并运行它时:
babel src --out-dir lib --presets react,latest
I get the following error: 我收到以下错误:
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)
I find this to be very strange because I made sure to install the latest
preset as is evidenced by the existence of the node_modules/babel-preset-latest/
directory. 我觉得这很奇怪,因为我确保安装了
latest
预设,这可以通过node_modules/babel-preset-latest/
目录来证明。
And everything works completely fine otherwise. 否则一切都会完全正常。 What is it about the
latest
preset that is causing it to trip? 什么是导致它绊倒的
latest
预设? I've tried all of the following presets and they work just fine: es2015
, es2016
, es2017
. 我已经尝试了以下所有预设,它们的工作正常:
es2015
, es2016
, es2017
。 It's just the latest
preset that is tripping everything up. 这只是掀起一切的
latest
预设。
Any help on troubleshooting would be greatly appreciated. 任何有关故障排除的帮助将不胜感激。
EDIT: My package versions 编辑:我的包版本
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
See this tweet by @_jayphelps: 请参阅@_jayphelps的推文 :
If u experience errors w/ babel like "Invalid options type for" or "Logger.error" or similar, upgrade babel-core!
如果您遇到错误,如“无效选项类型”或“Logger.error”或类似内容,请升级babel-core! https://github.com/babel/babel/pull/3635
https://github.com/babel/babel/pull/3635
So try upgrading babel-core
and other Babel modules. 所以尝试升级
babel-core
和其他Babel模块。 You can do that with this command: 您可以使用此命令执行此操作:
npm i -D babel-core@latest
i
is a shortcut for install
, -D
adds the package to devDependencies
in package.json
(it's the same as --save-dev
), and @latest
installs the latest version available. i
是install
的快捷方式, -D
将包添加到package.json
devDependencies
(它与--save-dev
相同),并且@latest
安装可用的最新版本。
It turns out I was using my globally installed babel-cli
instead of using the locally installed one (which was the up-to-date one). 事实证明我使用的是全球安装的
babel-cli
而不是使用本地安装的(这是最新的)。
Everything worked smoothly once I ran it like this: 一旦我像这样运行它,一切顺利:
node_modules/babel-cli/bin/babel.js src --out-dir lib --presets react,latest
Thanks to all who helped. 感谢所有帮助过的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.