得到Webpack的错误 - 找不到礼物“es2015”

时间:2017-08-14 13:03:48

标签: webpack

ERROR in (webpack)/node_modules/process/browser.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/usr/local/lib/node_modules/webpack/node_modules/process"

这是我的webpack配置文件:

var path = require('path');

module.exports = {

  entry: [
  './src/App.js',
  ],
  output: { 
    path: path.resolve(__dirname, 'dist'), 
    filename: 'bundle.js'
  },
  module: {
    loaders: [
    {
      test: /\.js$/,
      exclude: ['node_modules'],
      loader: 'babel-loader',
      query: {
        presets: ['es2015', 'react']
      }
    }
    ]
  }
}

这是我的package.json文件:

{
  "name": "ab-site-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router-dom": "^4.1.2"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "html-loader": "^0.5.1",
    "webpack": "^3.5.4"
  }
}

我不知道这个错误意味着什么。我已经尝试让webpack工作好几天了。我得到的每个错误都没有帮助,尝试解决它会导致产生更多错误。我将不胜感激任何帮助。我有.babelrc个文件,其中包含两个预设es2015react。我见过互联网上的人告诉我要删除它..保留它。也许我的npm已经过时了?也许我的网站已经过时了?我没有做任何工作,我所做的一切只会让其他错误出现。

1 个答案:

答案 0 :(得分:1)

配置babel预设有两种主要方法:通过babel-loader选项

y=c(2.5,1,0,1.2,2,3,2,1,0,-2,-1,.5,2,3,6,5,7,9,11,15,23)
x <- 1:length(y)
reduced <- heuristicDownSample(x,y,10)

par(mfrow=c(1,2))
plot(x=x,y=y,type="b",main="original")
plot(x=reduced$x,y=reduced$y,type="b",main="reduced",col='red')

或通过.babelrc。有些人喜欢一种做事方式,有些人更喜欢另一种方式。我用.babelrc。

此配置适用于我:

webpack.config.js

  options: {
          presets: ['es2015', 'react']
           }
.babelrc

中的

{
        test: /\.(js|jsx)$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
        }
      }