碼迷,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      閱讀:3980      評論: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
0條  
登錄后才能評論!
? 2014 mamicode.com 版權所有 京ICP備13008772號-2
迷上了代碼!
25选5历史开奖结果百度