Home  >  Q&A  >  body text

javascript - webpack compilation error Couldn't find preset "react" relative to directory

webpack.config.js:

let webpack = require('webpack');
let path = require('path');

module.exports = {
    context:__dirname + '/src',
    entry:"./js/index.js",
    module:{
        loaders:[
          {
            test: /\.js?$/,
            exclude: /node_modules/,
            loader:'babel-loader',
            query:{
                presets:['es2015','react']
            }
          }
      ]
    },
    output:{
        path:__dirname + "/src",
        filename:"bundle.js"
    }
};

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "antd": "^2.1.0",
    "babel": "^5.8.23",
    "babel-core": "^6.24.1",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.24.0",
    "babel-preset-react": "^6.23.0",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "webpack": "^2.4.1",
    "webpack-dev-server": "^2.4.4"
  }
}
漂亮男人漂亮男人2682 days ago887

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:33:05

    webpack 配置没问题。报错应该是 babel query There’s a problem there.

    1. The first solution: presets:['es2015','react']map(require.resolve)

    2. If the first method is not solved, just put the query删掉,在根目录下新建.babelrcquery 这个jsonobject in it

    3. If the second problem is not solved, upgrade the babel version of the relevant plug-in and repeat the above steps.

    reply
    0
  • Cancelreply