码迷,mamicode.com
首页 > Web开发 > 详细

webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-env' from '...' - Did you mean "@babel/env"?

时间:2018-12-08 14:48:09      阅读:11731      评论:0      收藏:0      [点我收藏+]

标签:解决   ror   tps   error   npm   load   ati   pac   set   

  • webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module ‘babel-preset-env‘ from ‘...‘ - Did you mean "@babel/env"?
    原因:
    babel-core和babel-preset-env依赖被替换为@babel/core和@babel/preset-env,因为新版本的Babel7中对官方提供的依赖使用了命名空间@babel
    npm install babel-loader babel-core babel-preset-env --save-dev
    npm install babel-loader @babel/core @babel/preset-env --save-dev
    解决:
    在.babelrc文件或在webpack.config.js文件中,将原来的env替换为@babel/preset-env
// .babelrc

{
  "presets": [
    ["env",
      {
        "modules": false
      }
    ]
  ]
}
// webpack.config.js

module: {
    rules: [
        {
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
                loader: ‘babel-loader‘,
                options: {
                    presets: [‘env‘, { modules: false }]
                }
            }
        }
    ]
}
  • babel官方:https://babeljs.io/docs/en/babel-preset-env#browserslist-integration

webpack报错:Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-env' from '...' - Did you mean "@babel/env"?

标签:解决   ror   tps   error   npm   load   ati   pac   set   

原文地址:https://www.cnblogs.com/cag2050/p/10087554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!