简体   繁体   English

为什么Webpack在我的主目录中寻找预设?

[英]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.

相关问题 当我将我的预设配置为 commonjs 时,为什么我的 webpack babel 设置发出 ESM 要求? - Why is my webpack babel setup emitting ESM requires when I have configured my preset to commonjs? 为什么在构建 webpack.mix.js 时我的.css 文件不会出现在公共目录中? - Why won't my .css file show up in the public directory when building webpack.mix.js? 为什么使用Webpack-dev-server启动React App返回我的目录结构 - Why using Webpack-dev-server to start a React App returned my directory structure 为什么在ReactJS for React Hot Loader中出现“错误:找不到相对于目录的预设“反应热”…”? - Why the 'Error: Couldn't find preset “react-hot” relative to directory…" in ReactJS for React Hot Loader? 在Webpack中配置Babel-preset-stage-0 - Config Babel-preset-stage-0 in Webpack 在 webpack config 中定义多个 babel 预设配置 - Defining multiple babel preset configurations in webpack config 当我使用babel-preset-es2015和Webpack捆绑jsx文件(react.js)时,为什么“ this”未定义? - Why is 'this' undefined when I bundled the jsx file (react.js) using babel-preset-es2015 and Webpack? 为什么我会收到此 npm 错误:无法从“/home/directory”中找到模块“/home/directory” - Why do i get this npm Error: Cannot find module '/home/directory' from '/home/directory' 为什么webpack忽略index.js,尽管它与我的app.js位于同一目录中,但编译良好 - Why does webpack ignore the index.js although it's in the same directory of my app.js, which is compiled fine 无法使用 WebPack 运行 React 应用程序,因为它正在查看公共目录 - Can't run React app using WebPack because it's looking in the public directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM