When using create-react-app with custom-react-scripts I always end up with React 16 (latest) installed. Is there a way to create a new project with an older version, like React 15?
When using create-react-app with custom-react-scripts I always end up with React 16 (latest) installed. Is there a way to create a new project with an older version, like React 15?
If you're here because of react v18, and you want to go down to the previous non-change breaking version, here's what i did:
in your package.json replace:
"react": "^18.0.0"
"react-dom": "^18.0.0"
with
"react": "^17.0.2"
"react-dom": "^17.0.2"
Then go to your entry file index.js
At the top, replace:
import ReactDOM from 'react-dom/client'
with
import ReactDOM from 'react-dom';
Still in your index.js file, replace:
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
with
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
node_modules and run yarn installyarn startIt seems that you can just go ahead and use it to generate a React 16 app, then edit package.json and run npm i (or npm install; npm i is just a shortcut).
I just left the react-scripts version at the latest version and only changed the versions of react and react-dom, and it worked:
"devDependencies": {
"react-scripts": "1.0.14"
},
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
Complementing the answers described above, after all the manipulation, I had to update this libs(for TS template) :
"@testing-library/react": "^12.1.1",
"@testing-library/user-event": "^12.5.0"
If you already created with React 18, you can downgrade version 18 to previous verions of react with a few steps.
You will need to do modifications in two files which are package.json and index.js . You should delete also node_modules
Step 1
Your index.js probably looks like this now
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
You should change import of ReactDOM and cancel const root line
New code of index.js should be like this
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
Step 2
Go to your package.json file and update desired react version in dependencies
"dependencies": {
...
"react": "^17.0.0",
"react-dom": "^17.0.0",
...
},
Step 3
Delede your node_modules and If you are using npm do npm i. If you are using yarn do yarn install. After this step you are good to run app with npm start or yarn start.
Step 4 (OPTIONAL: If you are still having problems but I do not recommend doing it)
Delete your package-lock.json (for npm) or yarn.lock file (for yarn) and start back from Step 3
I ran into this problem, especially with the new create-react-app v18. All I did was to delete my package-lock.json file and also my node_modules folder. I edited package.json afterwards, replaced react-dom and react with the version that I want as below:
"react": "^17.0.2",
"react-dom": "^17.0.2",
Finally, I installed my packages again using npm install
npx create-react-app app-name
it will always install latest react packages. Then, in react 18.2.0, It is some of different about previous version.
You go to your folder file structure and delete both package-lock.json ( yarn.lock for yarn) file and node_modules file.
After you go to your package.json file and change and edit these dependencies :
"react": "^18.2.0",
"react-dom": "^18.2.0",
to
"react": "^17.0.2",
"react-dom": "^17.0.2",
in your package.json dependencies file like this.
index.js file change,import ReactDOM from 'react-dom/client'
to
import ReactDOM from 'react-dom';
index.js file and change below part of index file.const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
to
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
terminal and runif you are using npm -->> npm install
and after the installing part you can run app npm start.
or
if you are using yarn -->> yarn install
and after the installing part you can run app yarn start.
--Thank You-- --Happy Coding--
First you have to install npm in your system Then For Create react app you have to run below command
sudo npm init react-app my-app --scripts-version 1.1.5
cd my-app
sudo npm install --save react@16.0.0
sudo npm install --save react-dom@16.0.0
It worked like a charm for me.
It's WORKED for me..
Run This Command
npm uninstall react
2.Then install React 17.0.2 Just run this command.
npm install react@17.0.2
For installing react-dom version 17.0.2 run this command.
npm install --save react-dom@17.0.2
Specify your script version while create project
sudo npm init react-app appname --scripts-version 1.0.13
its working for me