I seem to have react-scripts and webpack in conflict. There is a small project with such configs:

package.json

 { "name": "todo_react", "version": "0.1.0", "private": true, "dependencies": { "react": "^16.3.2", "react-dom": "^16.3.2", "react-scripts": "1.1.4" }, "scripts": { "start": "webpack", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "devDependencies": { "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "webpack": "^4.8.1", "webpack-cli": "^2.1.3" } } 

First, instead of "start": "webpack" was "start": "react-scripts start", однако при выполнении команды npm start` command, an error occurred:

Cannot read property 'thisCompilation' of undefined

Config for webpack such:

 var path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: "babel-loader" }, { test: /\.jsx?$/, exclude: /node_modules/, use: "babel-loader" }, { test: /\.css$/, use: [ { loader: "style-loader" }, { loader: "css-loader" } ] } ] } }; 

I said that this error may occur due to the simultaneous presence of react-scripts and webpack in package.json. It is even advised to remove node_moules , webpack and reinstall everything. And how can it be easier to solve this problem?

I need the ability to conveniently run the project using npm start and use the webpack.

  • if you pay attention, there is such a script in building facebook on the start command, perhaps this is the problem: "start": "cd packages / react-scripts && node bin / react-scripts.js start", - Romany

1 answer 1

The official build from React developers is the github repository ( https://github.com/facebook/create-react-app ). All configuration files are configured as needed, after installation, you can immediately write the application without thinking about how to make babel friends with the webpack. It is enough to have only NPM to deploy the project. Install it and there everything is already configured by default and in the future when adding libraries will follow the correct installation.

 npm install -g create-react-app create-react-app my-app cd my-app/ npm start