[英]Why is Webpack looking for a preset in my home directory?
In the Webpack for a project I'm working on, I have Webpack set to do Babel transpiling so I can use Flow-typed JavaScript. 在我正在处理的项目的Webpack中,我已将Webpack设置为进行Babel转译,以便可以使用Flow类型的JavaScript。 However, when I run Webpack, which has this rule, 但是,当我运行具有此规则的Webpack时,
{
test: /\.js/,
exclude: ['/node_modules/'],
use: [{
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: ['transform-flow-strip-types']
}
}]
}
I'm getting: 我越来越:
Module build failed: Error: Couldn't find preset "transform-flow-strip-types"
relative to directory "/home/andy"
Last time I was working on this, Webpack worked correctly and was searching for transform-flow-strip-types in my node_modules folder, but now it's looking in my home directory. 上一次我进行此操作时,Webpack可以正常工作,并且正在我的node_modules文件夹中搜索transform-flow-strip-types,但是现在它在我的主目录中。 Why would Webpack all of a sudden by looking in my home directory, or how would I be able to diagnose why that is? 为什么要在我的主目录中突然浏览Webpack,或者我怎么能够诊断出为什么?
This is an unfortunate footgun in Babel's config file parsing. 这是Babel配置文件解析中的不幸脚步。 It has traversed all the way out of your project and found an unrelated .babelrc
file that is in your home directory. 它遍历了您的整个项目,并在您的主目录中找到了一个不相关的.babelrc
文件。
There's pretty much never a reason to have a .babelrc
there, so your best bet would be to delete /home/andy/.babelrc
. 几乎没有理由在那里拥有.babelrc
,因此最好的选择是删除/home/andy/.babelrc
。 Alternatively if that's actually something your wanted (if so, please reconsider :P), you could create a no-op .babelrc
in your project with just an empty object in it, which would also fix the issue. 另外,如果这实际上是您想要的(如果需要,请重新考虑:P),则可以在项目中创建一个no-op .babelrc
,其中只包含一个空对象,这也可以解决此问题。
I'm currently working to make Babel stop searching for .babelrc
files as soon as it finds any package.json
but that has yet to land and would only apply to Babel 7.x, not the current 6.x release. 我目前正在努力使Babel在找到任何package.json
立即停止搜索.babelrc
文件,但是该文件尚未着陆,仅适用于Babel 7.x,不适用于当前的6.x版本。 https://github.com/babel/babel/pull/7358 https://github.com/babel/babel/pull/7358
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.