2

Every time I create a create-react-app project it throws this error:

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

  "babel-loader": "8.0.4"

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

  /Users/dalegrant/Desktop/hyberchat-dashboard/client/node_modules/babel-loader (version: 8.0.5)

I have tried downgrading to 8.0.4,

I've tried installing 8.0.5

I've even made sure all my dependencies for babel rely on a 8.0.5!

I have no idea what to do from here as the error persists for every create react app I now build!

This must be a common problem, does anybody have an idea on how to get around this?!

Sparlarva
  • 790
  • 1
  • 8
  • 30
  • According to warning message- You don't have to install babel-loader. If you already did, uninstall or just remove node modules directory. remove this from the package manager. Create React App will automatically add all required dependencies – PPB Mar 23 '19 at 11:13
  • `I've tried installing 8.0.5` that was a mistake... – Jonas Wilms Mar 23 '19 at 11:13
  • PPB i tried that many many times and then resorted to installing it, Jonas – Sparlarva Mar 23 '19 at 11:42
  • 1
    @Sparlarva start by installing [yarn](https://yarnpkg.com/lang/en/) - it's much easier to [manage peer dependencies](https://yarnpkg.com/lang/en/docs/managing-dependencies/) using yarn rather than npm in my experience – Rachel Gallen Mar 23 '19 at 12:31

3 Answers3

2

In your machine user folder there is a node_modules directory and package-lock.json remove them using rm -rf User/node_modules and rm -rf User/package-lock.json after that delete node_module directory and pack-lock.json file in your project run npm install again then it's works

Yesith
  • 660
  • 4
  • 10
1

Remove the babel-loader package (also globally):

  npm uninstall babel-loader
  npm uninstall babel-loader -g

Then run create-react-app again, it should install the correct dependency.

If you use the babel-loader somewhere else, pin the dependency there to ensure this problem does not happen again.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • Hi I'm just about to try this, when you say 'pin the dependency' what does that mean? could babel-loader being installed in some directories/projects affect others? – Sparlarva Mar 23 '19 at 11:23
  • @sparlarva yes, if installed globally. – Jonas Wilms Mar 23 '19 at 11:27
  • It wasn't installed globally, I removed it locally from all 4 of my applications anyway and now i'm trying to create a new one, I have a feeling the same problem will crop up – Sparlarva Mar 23 '19 at 11:28
  • I don't have it installed globally, I have the same error creating a new react app! – Sparlarva Mar 23 '19 at 11:30
0

you probably installed node_modules in your main folders before. Search for them and remove. In my case i have installed node_modules on my Home folder. When i removed files from this directory problem disapeared

MajkelEight
  • 107
  • 1
  • 8