react-scripts 5.0.0 bringing in extra webpack dependency

Viewed 186

I have an existing project updating to react-scripts@5.0.0. Trying to build or run the dev server is resulting in

TypeError: The 'compilation' argument must be an instance of Compilation

Following recommendations that this is due to conflicting webpack versions I found the following in my node_modules.

node_modules/webpack
node_modules/react-scripts/config/webpack
node_modules/react-scripts/node_modules/.bin/webpack <--- the culprit
node_modules/react-scripts/node_modules/webpack

If I generate a fresh project using CRA all works find and node_modules looks like this

node_modules/webpack
node_modules/react-scripts/config/webpack

Deleting the extra webpack under node_modules/react-scripts/node_modules/ makes my project start working but running an npm install causes it to come back.

Where could this be coming from? Why does my project bring this in but a fresh CRA project does not?

Update 1

I should mention that adding overrides to my package.json didn't help.

"overrides": {
    "webpack": "5.70.0"
  }
1 Answers

Removing the corresponding react-scripts/node_modules/webpack entries from package-lock.json cleared this up.

Related