Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create React App Dependency Issue with Webpack

Tags:

npm

reactjs

I am going through Lynda's Learning React course. In the second video of the 3rd chapter I am facing an issue. When I type npm start on Git Bash, the following error is being displayed:

$ npm start

> [email protected] start C:\Users\John\Desktop\Ex_Files_Learning_Reactjs\Files\Ch03\03_02\start\bulletin-board
> react-scripts start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "webpack": "4.19.1"

Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

  C:\Users\John\node_modules\webpack (version: 2.5.1)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if C:\Users\John\node_modules\webpack is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls webpack in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\John\AppData\Roaming\npm-cache\_logs\2018-10-09T09_26_01_403Z-debug.log

I have followed number 1 and 2 step. But I face an issue with step 3, there is no "webpack" from dependencies and/or devDependencies in the package.json file in my project folder.

So, I followed Step 4 and run npm start. But I am getting the same massive lines of error. What should I do to fix the issue?

My npm version is 5.6.0.

I am stuck and can't proceed further to the course without fixing it. NPM has been very irritating for me. I was doing a course on Angular and face a lot of issue with NPM. Now, I am doing a React course and once again, I am affected with tons of issues. It's really annoying.

Update: Here are the codes in package.json:

{
  "name": "bulletin-board",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-scripts": "^2.0.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
like image 405
john Avatar asked Oct 09 '18 09:10

john


People also ask

Can you use create react app with webpack?

Create-React-App is a great tool to bootstrap React apps, but it offers only limited access to the configuration of the production build. While it uses Webpack under the hood, the WebPack configuration is not exposed to the user - unless you decide to eject .

Does create react app do tree shaking?

If you're using modern tooling, such as webpack, create-react-app and similars, you already have tree shaking set up.

What is the difference between create react app and webpack?

Configuring webpack provides complete control over the development environment, while initializing with Create React App prevents any custom configuration by default.


1 Answers

Yes, I had the same issue.
I just deleted node_modules in the main directory at C:\Users\username.
Then, ran npm start, and it worked.

like image 113
JuleaJ Avatar answered Oct 17 '22 01:10

JuleaJ