错误:找不到预设的“反应"当使用npm install安装时--global babel-preset-react但可以在没有全局标志的情况下工作 [英] Error: Couldn't find preset "react" when installed using npm install --global babel-preset-react but works without global flag
问题描述
我使用npm install --global babel-cli
安装了Babel CLI(版本6).然后,我使用npm install --global babel-preset-react
安装react预设.
I installed Babel CLI (version 6) using npm install --global babel-cli
. I then install react preset using npm install --global babel-preset-react
.
然后我将项目目录中的.babelrc
文件设置为
I then setup the .babelrc
file in the project directory to
{
"presets": ["react"]
}
当我尝试构建JSX文件时,它失败并
When I try to build a JSX file it fails with
Error: Couldn't find preset "react"
at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:310:17)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:270:12)
at OptionManager.addConfig (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:206:10)
at OptionManager.findConfigs (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:347:16)
at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:392:12)
at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:191:75)
at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:122:22)
at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:53:22)
at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:62:12)
如果我安装不带--global标志的预设(即安装在本地的node_modules/文件夹中),则构建有效.如何设置以使babel与全局预设一起使用?
If I install the preset without --global flag (i.e. installs in node_modules/ folder locally) then the build works. How do i set up to get babel to work with a global preset?
推荐答案
您可以指定要使用的预设的绝对(或相对)路径,例如:
You can specify the absolute (or relative) path to the preset you are trying to use, e.g:
babel --presets /usr/local/lib/node_modules/babel-preset-react --watch jsx/ --out-dir js/
这篇关于错误:找不到预设的“反应"当使用npm install安装时--global babel-preset-react但可以在没有全局标志的情况下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!