Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-react-app installs [email protected] causing peer dependency #13717

Open
Yangbao-Jin opened this issue Dec 7, 2024 · 35 comments
Open

Comments

@Yangbao-Jin
Copy link

Describe the Bug
When creating a new React app using npx create-react-app myprog, the installation fails due to dependency resolution issues. Specifically, create-react-app installs [email protected] by default, which conflicts with dependencies like @testing-library/[email protected] that require react@"^18.0.0". This problem persists even when using the --legacy-peer-deps flag or specifying [email protected].

Did you try recovering your dependencies?
Yes, I followed the suggested recovery steps:

Deleted the node_modules, package-lock.json, and yarn.lock (if applicable).
Reinstalled dependencies with npm:
bash
複製程式碼
npm install -g npm@latest
npm install
Used a clean directory for npx create-react-app.
Despite these efforts, the issue persists.

Which terms did you search for in User Guide?
I searched the following terms in the Create React App Documentation:

"dependency conflict"
"peer dependency"
"react@19"
"legacy-peer-deps"
None of the solutions resolved the issue.

Environment
Here is the output of npx create-react-app --info:

yaml
複製程式碼
Environment Info:

current version of create-react-app: 5.0.1
running from /Users/jim/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System:
OS: macOS 14.6.1
CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Binaries:
Node: 22.12.0 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.9.2 - ~/.npm-global/bin/npm
Browsers:
Chrome: 131.0.6778.71
Edge: Not Found
Safari: 17.6
npmPackages:
react: Not Found
react-dom: Not Found
react-scripts: Not Found
npmGlobalPackages:
create-react-app: Not Found
Steps to Reproduce
Install Node.js LTS version (22.12.0).
Run npx create-react-app myprog or npx create-react-app myprog --legacy-peer-deps.
Observe the dependency resolution error.
Expected Behavior
The project should initialize successfully with compatible versions of react, react-dom, and all other dependencies. Specifically, it should install react@18 instead of react@19, as the latter is not yet compatible with the current create-react-app dependency chain.

Actual Behavior
The project initialization fails with the following error:

vbnet
複製程式碼
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react
npm error @testing-library/react@"^13.0.0" from the root project
Reproducible Demo
This issue occurs in a clean environment. Steps to reproduce:

Delete any existing node_modules or lock files:

bash
複製程式碼
rm -rf node_modules package-lock.json
Run:

bash
複製程式碼
npx create-react-app myprog
Alternatively, use:

bash
複製程式碼
npx create-react-app myprog --legacy-peer-deps
The issue persists in both cases.

Additional Notes
This issue appears to be caused by [email protected] being marked as the latest release on npm. However, @testing-library/react and other dependencies still require react@18.
I attempted the following workarounds, but none resolved the issue:
Specifying [email protected]:
bash
複製程式碼
npx create-react-app myprog --scripts-version [email protected]
Using --legacy-peer-deps:
bash
複製程式碼
npx create-react-app myprog --legacy-peer-deps
Manually installing react@18 and react-dom@18 before running create-react-app.
This appears to be an ecosystem issue that requires either:

A change in create-react-app to explicitly lock React to version 18.
Updates to dependencies like @testing-library/react to support React 19.

@DDZD20
Copy link

DDZD20 commented Dec 7, 2024

same problem

@christianmarch
Copy link

Same for me

@makostechsolutions
Copy link

same issue

1 similar comment
@varunesh-ram
Copy link

same issue

@DoozyDoz
Copy link

DoozyDoz commented Dec 7, 2024

same
work around at the moment is to use yarn

npm install -g yarn
yarn create react-app my-app

@adlternative
Copy link

same question

@InnocentLi
Copy link

i think you should change react to 18 in [you project]package.json `"dependencies": {
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.121",
"@types/react": "^18.3.14",
"@types/react-dom": "^18.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^3.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"ajv": "^7.2.4"
}
}
and use Node16

@JonesKhaii
Copy link

I have same problem when i run audit-fix-force a few days ago, react 19 so bad

@Yangbao-Jin
Copy link
Author

Yangbao-Jin commented Dec 8, 2024 via email

@JonesKhaii
Copy link

Thanks, but I’d like to create react project using just one command just as before: npx create-react-app myprog . without project folder, how can i change the package.json in the project folder? it’s chicken and eggs problem~ and i’d like to know why i can not use one command to create a react project all of a sudden? Best, Jim

On Dec 8, 2024, at 06:39, innocence @.> wrote: i think you should change react to 18 in [you project]package.json `"dependencies": { { "name": "test", "version": "0.1.0", "private": true, "dependencies": { @./jest-dom": "^5.17.0", @./react": "^13.4.0", @./user-event": "^13.5.0", @./jest": "^27.5.2", @./node": "^16.18.121", @./react": "^18.3.14", @./react-dom": "^18.3.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "^3.0.1", "typescript": "^4.9.5", "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "ajv": "^7.2.4" } } and use Node16 — Reply to this email directly, view it on GitHub <#13717 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKMXKRS2A3YOWZM32MSSZ632ERK3JAVCNFSM6AAAAABTF3KJZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRWGEYDINJTGY. You are receiving this because you authored the thread.

did you try "npm install react@18 react-dom@18" when finish create this project ? React 19 will change 18.3.1

@Yangbao-Jin
Copy link
Author

Yangbao-Jin commented Dec 8, 2024 via email

@Yangbao-Jin
Copy link
Author

Yangbao-Jin commented Dec 8, 2024 via email

@Levi-B4
Copy link

Levi-B4 commented Dec 9, 2024

https://stackoverflow.com/questions/71835697/create-react-app-dependency-version-issues-with-react-18

This fixes it, until the problem is updated.

[after creating the react app, with errors...]

  1. delete both "node_modules" and "package-lock.json"
  2. run npm i web-vitals --save-dev
  3. run npm install

@anshukumar-kiwi
Copy link

anshukumar-kiwi commented Dec 9, 2024

image
I am also facing this issue idk why it is coming. I am not able to run the create-react-app command.

@rosiehiggins
Copy link

same problem for me. I can't see that any tsconfig.json file was created

@elitekbtu
Copy link

how to solve the same problem? I thought I made the problem

@dschilling
Copy link

dschilling commented Dec 9, 2024

same work around at the moment is to use yarn

npm install -g yarn
yarn create react-app my-app

The workaround by @DoozyDoz does indeed work. Thanks Doozy!

The other suggested workarounds (edit package.json or run npm install) cannot work because they depend on the app already existing, but it doesn't yet because create-react-app cannot complete successfully. It fails partway through, leaving the app in a half-created state.

Actually - maybe they do work for a plain JS app - I don't know. I'm creating an app using the typescript template, and create-react-app fails before adding any typescript-specific pieces, and there's no way to ask it to resume because it expects the folder to be empty.

@juanbautistavp
Copy link

I'm having the same problem

@aymengraoui
Copy link

aymengraoui commented Dec 9, 2024

Hi everyone,

In the package json specify react and react-dom versions, this worked for me.

"react": "^18.0.0", "react-dom": "^18.0.0",

Cheers.

@wulianer
Copy link

wulianer commented Dec 9, 2024

https://stackoverflow.com/questions/71835697/create-react-app-dependency-version-issues-with-react-18

This fixes it, until the problem is updated.

[after creating the react app, with errors...]

  1. delete both "node_modules" and "package-lock.json"
  2. run npm i web-vitals --save-dev
  3. run npm install

This works for my case. Thanks.

Hope the React development team can quickly fix this. This is the entrance for a React project and it gives me a very bad image for the project quality. Now sure how the develop team can let this issue happen without a full test.

@axalix
Copy link

axalix commented Dec 10, 2024

Is this project abandoned? last commit was 4 months ago. Tons of opened issues and MRs with no attention.

@JoeBrar
Copy link

JoeBrar commented Dec 10, 2024

Same problem.
create-react-app installs @testing-library/react version 13.0.0 which is outdated and does not support the latest react version, hence causing the peer dependency.

@EJT21
Copy link

EJT21 commented Dec 11, 2024

Same problem

@ironman-z
Copy link

Temporary measures:
create-react-app/createReactApp.js
const allDependencies = ['react', 'react-dom', packageToInstall]; to
const allDependencies = ['react@^18.3.1', 'react-dom@^18.3.1', packageToInstall];

@TDaniel-evo
Copy link

I used create-vite to setup the boilerplate code for a react app: https://vite.dev/guide/#scaffolding-your-first-vite-project

@qaidjoharj53
Copy link

Having trouble with Create React App (CRA)? Consider switching to Vite, a modern build tool offering a faster, smoother React development experience.

Here's how to set up a new React project using Vite:

# Create new Vite project
npm create vite@latest my-react-app

# Navigate to project directory
cd my-react-app

# Install dependencies
npm install

# Start dev server
npm run dev

Switching to Vite can save time and reduce complexity, especially if you're encountering errors with CRA. Give it a try and let me know how it works for you!

@axalix
Copy link

axalix commented Dec 11, 2024

@qaidjoharj53 did you try it yourself? What React version have you got installed? Did you read the title?
This is what I am getting

    "@types/react": "^18.3.12",
    "@types/react-dom": "^18.3.1",

Vite doesn't maintain React 19 [yet]: vitejs/vite#18917

@qaidjoharj53
Copy link

@axalix I understand the title is about React 19.
I shared the Vite solution because, as of now, there are no official fixes from React or CRA for this issue.
While Vite doesn’t yet support React 19, this method provides a way for us developers to continue development workflow with React 18, avoiding CRA issues in the meantime.

@axalix
Copy link

axalix commented Dec 11, 2024

@qaidjoharj53 I appreciate your intention, but this thread is not about Vite, nor about React 18.

@Jjqcoder
Copy link

Jjqcoder commented Dec 13, 2024

It looks like a react19-related issue, and some react19-based websites are also inaccessible, such as https://designable-antd.formilyjs.org/

For details, please see this issue below:
alibaba/formily#4248

@Astralzz
Copy link

I have the same problem 😑

@zacharytyhacz
Copy link

Same issue here with typescript template

> npx create-react-app new-client --template typescript

Creating a new React app in /Users/zact/Projects/new-client.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...


added 1320 packages in 11s

265 packages are looking for funding
  run `npm fund` for details

Initialized a git repository.

Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^19.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from @testing-library/[email protected]
npm ERR! node_modules/@testing-library/react
npm ERR!   @testing-library/react@"^13.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! /Users/zact/.npm/_logs/2024-12-14T03_33_42_989Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/zact/.npm/_logs/2024-12-14T03_33_42_989Z-debug-0.log
`npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 @types/jest@^27.0.1 @types/node@^16.7.13 @types/react@^18.0.0 @types/react-dom@^18.0.0 typescript@^4.4.2 web-vitals@^2.1.0` failed

@rodionmern
Copy link

same problem

@carlosamcruz
Copy link

image I am also facing this issue idk why it is coming. I am not able to run the create-react-app command.

If you put './App.tsx' the problem is gone. For some reason we need to put extension in this version.

@carlosamcruz
Copy link

carlosamcruz commented Dec 15, 2024

@axalix I understand the title is about React 19. I shared the Vite solution because, as of now, there are no official fixes from React or CRA for this issue. While Vite doesn’t yet support React 19, this method provides a way for us developers to continue development workflow with React 18, avoiding CRA issues in the meantime.

They would make CRA not support React 19 also. I tried Next.js and it did not solve my problem, because when I use fs dependencies it says you cannot run it on the client side. It wants to force me to use it on the BackEnd, but I want to use it on the frontEnd. Will Vite solve this issue?

`./node_modules/fs.realpath/old.js:24:10
Module not found: Can't resolve 'fs'
22 | var pathModule = require('path');
23 | var isWindows = process.platform === 'win32';

24 | var fs = require('fs');
| ^^^^^^^^^^^^^
25 |
26 | // JavaScript implementation of realpath, ported from node pre-v6
27 |

https://nextjs.org/docs/messages/module-not-found`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests