'New React app failed to compile immediatly following install
I have been using React Native for a while but figured I would try out React on the web. So I followed this guide: https://reactjs.org/docs/create-a-new-react-app.html but after using npx create-react-app react-try
, navigating to the new folder, and typing yarn start
I get this error message:
Failed to compile.
./src/index.js 1:60
Module parse failed: Unexpected token (1:60)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> $RefreshRuntime$ = require('C:/Users/e096752/Documents/Cole's Git Repos/react-try/node_modules/react-refresh/runtime.js');
| $RefreshSetup$(module.id);
This is everything that was included with the create method: Project
Package.json
{
"name": "react-try",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"web-vitals": "^1.0.1"
},
"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"
]
}
}
If there is any other info you need please let me know. What in the world do I need to do?
Solution 1:[1]
There appears to be a problem with
react-scripts 4.0.2.
A workaround is to change version manually to 4.0.1 on package.json then run yarn install
.
That will do!
Solution 2:[2]
this problem happened for me because of the single quotation in the folder name, removing it solved the issue.
Solution 3:[3]
package.json -> change version to 4.0.1 in "react-scripts": "4.0.1" ->run npm install again
Solution 4:[4]
Just followed the terminal log and the issue was resolved:
- Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
- Delete node_modules in your project folder.
- Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
- Run npm install or yarn, depending on the package manager you use.
Solution 5:[5]
I used this below npm command. I get out of this problem. let's try once this npm link
Solution 6:[6]
If your folder name has quotation marks like sample'app / "sample app", remove those quotation marks or delete folder and create app react app from first.
Solution 7:[7]
First update your react-scripts
and remove webpack from your packages.json if you added.
Then you need to clear webpack cache so for doing this the ease way is remove node_modules
and install them again
Solution 8:[8]
This mostly happens with loaders when one or more of the directories in your source file URL has an apostrophe.
in my own case it was;
$ react-scripts start Failed to compile.
./src/index.js 1:43 Module parse failed: Unexpected token (1:43) File was processed with these loaders: ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.jsYou may need an additional loader to handle the result of these loaders.> $RefreshRuntime$ = require('C:/Users/PETER'S/PROJECTS/REACT APPS/EGAS/egas/node_modules/react-refresh/runtime.js');| $RefreshSetup$(module.id);
you can quickly fix this by opening this file;
"*Project root directory*\node_modules@pmmmwh\react-refresh-webpack-plugin\loader\RefreshModule.runtime.js"
then change this line;
$RefreshRuntime$ = require('$RefreshRuntimePath$');
to the absolute URL equivalent (in my case);
$RefreshRuntime$ = require("C:/Users/PETER'S/PROJECTS/REACT APPS/project-root/node_modules/react-refresh/runtime.js");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | fabiangamboa95 |
Solution 2 | I3B |
Solution 3 | Wojciech Procelewski |
Solution 4 | Mahan Mashoof |
Solution 5 | Naveen V |
Solution 6 | Manu |
Solution 7 | Hossein Mohammadi |
Solution 8 | sbgib |