53

All I am doing is running create-react-app and cd'ing into the app, then trying to run npm/yarn start. I get the following error/output/log. I have walked through all of the suggested steps. The only thing that works is the SKIP_PREFLIGHT_CHECK=true in my .env as the last resort for both Yarn and npm. I have recently updated to Mojave and had to reinstall my Xcode if people have had a similar experience.

Last login: Tue Oct 30 16:30:24 on ttys002
TheLAB11:~ jasonspiller$ cd repos/react-express-graphql-app/
TheLAB11:react-express-graphql-app jasonspiller$ npm start

> react-express-graphql-app@0.1.0 start /Users/jasonspiller/repos/react-express-graphql-app
> 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:

  "babel-jest": "23.6.0"

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

  /Users/jasonspiller/node_modules/babel-jest (version: 23.4.2) 

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 "babel-jest" 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 /Users/jasonspiller/node_modules/babel-jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

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

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! react-express-graphql-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-express-graphql-app@0.1.0 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!     /Users/jasonspiller/.npm/_logs/2018-10-30T23_09_42_358Z-debug.log
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
jasonspiller
  • 543
  • 1
  • 4
  • 6

23 Answers23

47

I just had the same problem. For some reason the package ended up in a node_modules directory in my home directory. It also gave me the exact same error for the jest package.

I'm not sure of the correct way to fix this as npm uninstall -g babel-jest and yarn global remove babel-jest do not do anything.

I fixed it by just blowing away the folders that cause the problem: bash rm -rf ~/node_modules/babel-jest ~/node_modules/jest

It would be great to know how those packages ended up there, and the proper way of getting rid of them, but for now just deleting the folders is enough to get CRA dev server running without skipping the preflight check.

Wade J
  • 738
  • 1
  • 7
  • 13
  • 2
    Thank you so much. Like you say, maybe not the _correct_ way, but works for me. Thanks again. – jasonspiller Nov 02 '18 at 17:41
  • 2
    I encountered this exact error as reported in OP, and followed this exact advice above. I had to delete 1 further module in the same way (`rm -rf ~/node_modules/webpack`) ... then my app launched with `yarn start`. – olisteadman Feb 06 '19 at 08:39
  • 2
    This solution is not accepted as after every new npm install problem persists back. Though a good workaround but not a solution. – ManMohan Vyas May 07 '19 at 12:57
  • 1
    I tried all the above-mentioned and also `https://blog.travis-ci.com/2014-08-14-new-cache-ui/` was helpful. I added in the travis file `travis cache --delete` – Steven May 03 '21 at 16:22
  • 1
    remove everything it throws at you, in my case: rm -rf ~/node_modules/webpack-dev-server ~/node_modules/jest rm -rf ~/node_modules/webpack ~/node_modules/jest rm -rf ~/node_modules/eslint ~/node_modules/jest rm -rf ~/node_modules/babel-loader ~/node_modules/jest – Claudiu Haidu Feb 17 '23 at 17:03
40

This problem can occur if there is node_modules in a parent directory of the folder where you run the application. I solved the problem by deleting the node_modules directory.

Ahmet Şimşek
  • 1,391
  • 1
  • 14
  • 24
  • 8
    This was my case – VictorC Jan 13 '19 at 17:30
  • 3
    I also ran into this, but removing the parent directory wasn't an option. I was able to get past it by ensuring both `babel-jest` and `jest` in both directory were the same version. – dimroc Mar 25 '19 at 16:25
  • That was also my case. Thanks! – Rafael Cavalcante May 02 '19 at 04:02
  • 1
    parent directory does not contain node_modules directory still there is problem – ManMohan Vyas May 07 '19 at 12:57
  • That was my case too. – Ahmed Ayoub May 18 '19 at 10:04
  • My case as well. My "Projects" root folder had gotten a node_modules directory accidentally by some other mistake. I deleted node_modules folder in the parent folder and it now works. Thanks – Petter Kjelkenes Jun 06 '19 at 11:48
  • 1
    I read this one thinking "That is so dumb, no way is that the solution." Two seconds later I am back to upvote. – rob5408 Jun 24 '19 at 20:29
  • 1
    this was my case as well. A node_module folder that was in the home directory where I keep all my projects under – John Jun 25 '19 at 02:33
  • This. In my Dockerfile, I was copying my CRA app into a path where there was a node_modules folder in the parent directory. Sneaky! – Jordan Dodson Jul 15 '20 at 05:22
  • Thanks for this helpful info, the lengthy solution provided by npm is soooo misleading! There is no babel-jest at all in my package.json, so much time wasted :( – Calvin Zhou Aug 08 '20 at 15:24
  • I am running the application from GitHub folder and thinking how's it possible to have an outside folder having "node_modules". After re-checking In Mac GitHub folder is part of "username/Documents/Github". Deleted the node_modules folder at the username folder level. Then it worked for me. Thank you so much. – Sai kumar Sep 14 '22 at 05:10
24

I too faced a similar problem and was able to resolve the issue following below steps.

  1. Create a .env file in your project root directory and add the following statement

SKIP_PREFLIGHT_CHECK=true

  1. Save the file

  2. Remove node_modules, yarn.lock, package.lock

  3. Then reinstall node_modules with

npm install

This should work

Rajesh
  • 4,273
  • 1
  • 32
  • 33
  • 1
    I recently changed my .env file and did not have SKIP_PREFLIGHT_CHECK=true, adding this back on helped solve this problem. I did not need to do any deleting, just restart the app after changing the .env. Another fix was deleting the culprit modules from the home directory i.e. global installs, however, the problems come back as you bring on global tooling with deps over time – NewScientists Dec 03 '19 at 07:31
  • 2
    In my case there was no need to delete node_modules or .lock files. just added .env file with the SKIP_PREFLIGHT_CHECK=true did the trick – sina farbod Jan 25 '21 at 12:23
22

The problem seems to have reappeared in create-react-app 3.0.0.

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

  "babel-jest": "24.7.1"

As abisuq pointed out in https://github.com/facebook/create-react-app/issues/6756#issuecomment-489562571 adding a version resolutions into package.json temporarily fixes the problem.

"resolutions": {
  "babel-jest": "24.7.1"
},

Update: It has been fixed in create-react-app 3.0.1. If upgrading is an option you can run

npm install --save --save-exact react-scripts@3.0.1

or

yarn add --exact react-scripts@3.0.1
Martin Fahl
  • 937
  • 2
  • 12
  • 28
  • 1
    At the moment, this seems the only working fix. I used it with `yarn cache clean` and removing of the `node_modules` + `yarn.lock` – roNn23 May 15 '19 at 12:49
  • Agreed, the same problem is in create-react-app 3.0. I used the workaround for resolution. If any one is able to solve the problem please share. – Signcodeindie May 15 '19 at 13:22
  • create-react-app 3.0.1 is out now, seems to be fixed there. So a solution can be to run `yarn upgrade --latest create-react-app`. – ArneHugo May 16 '19 at 13:16
  • i start getting this issue with the latest create-react-app 4.0.3 after i install react-chessground :/. – dtc Oct 11 '21 at 00:32
5
  1. run: npm ls babel-jest

got : babelk-jest@24.7.1 & babel-jest@24.8.0 installed

this means install tow babel-jest with diff version

  1. run:npm uninstall babel-jest@24.8.0 fix my issue
leaez
  • 51
  • 1
  • 4
5

I had this issue and finally solved it easily. As probably you know, when we use create-react-app, Jest is configured by default and you don't need to install Jest (when we use Webpack, we can install Jest). So, if you use Create-react-app and install Jest by mistake:

  1. Firstly uninstall it (remember that if you use: (npm install --save-dev jest), you can remove jest directly from Package.json or use: (npm uninstall --save-dev jest)
  2. Delete package-lock.json (not package.json)
  3. Delete the node_modules
  4. npm install

Now you don't receive an error and you can easily use: (npm start) or (npm test)

Also, It is worth mentioning that I installed the following tools to write my test in React component: (npm install --save-dev enzyme enzyme-adapter-react-16 jest-enzyme) and wrote my test by using jest and enzyme. Then I easily use: (npm test)

Good Luck!

Nasser
  • 51
  • 1
  • 4
5

Ok I finally found a solution after trying everything. Here is what finally worked:

  • First of all, read the error message in the cmd from the beginning. They'll tell you what module is causing the problem. You probably have an older version installed on your computer. Example: babel-jest version 2.4.4
  • Go to your Node.js folder c:/Users/(your user)/node_modules and find that module and simply delete it.
  • Go back to the cmd and run npm start. You might get the same error. But it'll be for a different module. Just delete it the same way and repeat until it runs.
Ali Alsabe
  • 51
  • 1
  • 2
  • Nothing else I tried worked, but this did the trick on Windows 10. Use this if reinstalling the packages locally doesn't work! – omni Jun 06 '20 at 06:37
3

I fixed the issue by removing the node_modules folder and package-lock.json file from a folder that was higher than the root of the project. I had installed node_modules accidentally in a higher folder.

I had:

  • desktop/code/node_modules (remove this to fix)
  • desktop/code/package-lock.json (remove this to fix)
  • desktop/code/project/node_modules
  • desktop/code/project/package-lock.json
Derek
  • 31
  • 2
1

I was having this issue as well. When I tried to run the client using npm start, the error would occur, telling me that it required babel-jest: ^24.9.0.

I noticed that in my client, babel-jest was version ^24.9.0, but in my server, I had "jest": "^26.6.3".

All I had to do was change "jest": "^26.6.3" to "jest": "^24.9.0" in the server side source code, delete my package-lock.json as well as node_modules in server, npm install again, and good to go!

1
  • At first I installed these (my react version was "^17.0.2")
    1. npm install --save-dev jest

    2. npm install --save-dev enzyme enzyme-to-json

    3. npm install @wojtekmaj/enzyme-adapter-react-17

  • After that, I had the same problem.
  • Then I did these steps :)
    1. Added '.env' file in my project root directory and add: SKIP_PREFLIGHT_CHECK=true
    2. Removed node_modules & package.lock
    3. npm install

    4. npm start

0

I had the exact same issue. What I tried was to create the react app outside the directory that had the node_modules folder. After that, started the app with yarn start and didn't have the error anymore.

0

I had the same problem, and I fixed this issue. For some reason because node_modules on my local. I removed babel-jest & jest. After that, npm start. I'm not sure this solved incorrect but this correct for me.

Blue Tram
  • 161
  • 1
  • 5
0

I solved this issue by deleting the node_modules folder and package-lock.json file I accidentally had installed in the root of my user.

For me in Mac the path was:

Macintosh HD -> Users -> "My-user-name"

I discover that might be the problem by running npm ls babel-jest on terminal. That showed me that there was another babel-jest up in the tree.

After deleting these two I did npm install in my app where I previously had deleted the node_modules folder and package-lock.json.

Now it's running ok !

0

I fixed this by deleting node_module folder in the project directory

0

try this command and see which packages create conflicts in versions.

npm ls babel-jest

replace the conflicted packages with updated one of that package.

SaimumIslam27
  • 971
  • 1
  • 8
  • 14
0

I tried all of written solutions above. But none of them worked. I solved problem by deleting "C:\node_modules" folder. Then delete project node_modules and package-lock.json. Finally, npm install and start again. And it worked.

realist
  • 2,155
  • 12
  • 38
  • 77
0

My react-scripts version is 4.0.3. The problem suddenly happened after installing a private remote package, which installed multiple babel packages in my project root's node_modules. I solved this by installing the problematic packages on the project root's level explicitly, so that they match the versions reported in the preflight check.

Following addings fixed it in my case. Your needed packages and versions may differ, you have to check the preflight report.

yarn add babel-jest@^26.6.0
yarn add babel-loader@8.1.0

For me its still a workaround, but i prefer this way instead of removing something in node_modules manually as suggested in https://stackoverflow.com/a/53093421/4840661.

fabpico
  • 2,628
  • 4
  • 26
  • 43
0

This is the approach without deleting node_modules:

  • I recieved error like:

The react-scripts package provided by Create React App requires a dependency: "jest": "26.6.0" Don't try to install it manually: your package manager does it automatically. However, a different version of jest was detected higher up in the tree:

  • First check the versions using:

    npm ls babel-jest

    In my case output was like this:

jest@27.0.3
└─┬ @jest/core@27.0.3
└─┬ jest-config@27.0.3
└── babel-jest@27.0.2

  • After that uninstall babel-jest by
    npm uninstall babel-jest
    (When you see the single version of babel-jest,otherwise go as versions as follows)
    npm uninstall babel-jest@27.0.2

  • Then install required dependencies using
    npm i babel-jest@version jest@version
    (Where version is the one come in 1st point)

This works for me like a charm. Hope this solves you too.

0

Got this error in the netlify ci, here's the fix that worked for me: this method works for any lib i got a error for eslint instead of babel-jest.

  1. force the error to be shown by npm i -s @babel-jest/VERSION --force

    replace VERSION with whatever version shows in the error(23.6.0 in this case), the correct error message will be shown locally

  2. use https://www.npmjs.com/package/npm-check-updates to upgrade your package.json flie with the correct versions

    run ncu -u in dir of package.json after installing the npm package globally

  3. finally do a npm ci

    this will delete the package-lock and node_modules and install the new versions based on the second step

Gokul Kurup
  • 91
  • 2
  • 9
0

this work for me. clear caches in npm or yarn remove node_modules and lock files

  • create .env file
  • add " SKIP_PREFLIGHT_CHECK=true " to an .env file in your project.
LeulAria
  • 333
  • 3
  • 9
0

my issue was that I have both frontend and backend that I am running concurrently. I installed jest to my root project (for backend) and I guess there is collision with pre-installed react jest. I just uninstalled jest from backend and voila I am happy now. I don't have anything related with babel.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Hakim Asa
  • 443
  • 3
  • 15
0

In my case, it wasn't just babel-jest but also jest, babel-loader, all webpack packages and all eslint packages are packages. If you have these packages in your package.json, I would recommend removing all of them instead of painfully doing it one by one. This will definitely save you about an hour of knowing what packages shouldn't be there since you only see one package error at a time.

Nihal Dias
  • 79
  • 5
-4

i had the similar problem and wasted my 2-3 days The easiest way to solve this problem is :

1.go outside of src, and create .env file. 2.Inside .env file, just write this single line and save it: SKIP_PREFLIGHT_CHECK=true 3.then npm start

Hope this helps, Happy coding!!!