22

I have just started learning React and created a first app by using below commands npm install -g create-react-app npx create-react-app myapp after this i moved into my app folder and then used 'npm start' command to start the server but i go this error.enter image description here

Please help me to resolve this problem and starting the react server.

Lovepreet Singh
  • 321
  • 1
  • 7
  • 16

17 Answers17

70

If you have an & in your project's path you will run into this issue, at least on Windows it seems like. The part in the path after the & is interpreted as another command as per the error and everything breaks from there.

Confirming that as soon as it's removed, npm start works fine.

Voicu
  • 16,921
  • 10
  • 60
  • 69
14

It's happening most likely because of an & in your folder name which is getting used as the path of your project. So Check the whole path trail of your project and rename any folder with "&" to only text-based names.

The Run - npm start from the console. Hope it will solve your problem. Enjoy coding and changing the world.

Arijit Hajra
  • 141
  • 1
  • 2
9

this is happening because of one of the following reason -:

  • your project directory has & symbol in the name, this happens because when node encounters & symbols it breaks the string into 2, ( if you have worked with simple http authentication, you would know this issue )
  • delete you node_modules, package.lock.json, install both again and run start script - suitable for linux systems only,

If your problem still exists, re-install node in you system again, and check for & symbol in your project dir.

ignacio
  • 1,181
  • 2
  • 15
  • 28
Nilay Gupta
  • 133
  • 1
  • 5
  • I don't have & in my path. But after I remove node_modules and package.lock.json and then execute npm install. It works. Thanks. – Kai-Chun Lin Aug 16 '23 at 06:36
5

Its a pretty simple answer . I have not yet found out why it works but try this :

react-scripts build
Nikhil Kumar
  • 73
  • 1
  • 5
3

remove special character for example "&" in your local drive directory path, I had & in directory name and finally deleted and problem solved

messi
  • 31
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 10 '22 at 11:38
3

In your project path (Larsen & Toubro/react/myapp), there is a "&" symbol. Because of that, it will display the error. When rename that "Larsen & Toubro" folder without "&" symbol, the issue will fix.

Lakshani
  • 31
  • 2
3

In my case, my file directory has a "&" symbol I just remove this and symbol and this problem is solved

2

It looks like npm install not executed while app creation. What you can look for is:

  1. Check if package.json is inside myapp.
  2. If node_modules directory is not created then move to 3.
  3. Run npm install or yarn to load the scripts and other dependencies.
  4. When done installing then try npm start or yarn start.
Jai
  • 74,255
  • 12
  • 74
  • 103
  • 1. package.json is available inside myapp. 2.node_modules directory is already created. 3.Tried npm install to load the scripts and other dependencies and it did some installing then exit. 4.Tried npm start but still same error. – Lovepreet Singh Mar 29 '20 at 09:50
  • In `.npmrc` file do you have the registry url assigned? like this `registry=http://registry.npmjs.org/`. – Jai Mar 29 '20 at 09:52
  • I read somewhere that computer name is having space in it and this may cause some error. Is it correct or not as my PC name is having space in it. Moreover I created a same project but at different location which does not have any name space and there this project is working fine. – Lovepreet Singh Mar 29 '20 at 09:54
  • I don't think so that would create any issue and frankly speaking I haven't got any situation like yours. But sometimes same error happened to me and Point3 worked for me each time. – Jai Mar 29 '20 at 09:55
  • I didn't find .npmrc file anywhere in myapp folder and its subfolder. could you please tell me where to find it. – Lovepreet Singh Mar 29 '20 at 09:58
  • It gets created in the current user's directory like `C:/>/Users/"username"` – Jai Mar 29 '20 at 10:02
  • I didn't find this file anywhere in my C directory. Is there any chance my installation has gone wrong? or there is something more to it. – Lovepreet Singh Mar 29 '20 at 10:10
  • You have to go in `C` dir then `Users` dir then `Lovepreet Singh`. `<---here` that file will be somewhere if it is not there then you can use bash to create it with `touch .npmrc` but you should run it in your `Lovepreet Singh` dir. then run this command `npm config set registry http://registry.npmjs.org/`. Or you can open this file in a text editor then put this line `registry=http://registry.npmjs.org/` – Jai Mar 29 '20 at 10:22
  • Created that file, added that line, saved it and run npm i and the npm start but still same error – Lovepreet Singh Mar 29 '20 at 10:32
2

Please check with the Project path conatins "&". This is the major cause of the issue. My issue got fixed after removing the C:*R&D*\REACTJS\thepage from the path.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 17 '21 at 20:44
2

I edited my package.json file:

"scripts": {
    "start": "node node_modules/react-scripts/scripts/start.js",
    "build": "node node_modules/react-scripts/scripts/build.js",
    "test": "node node_modules/react-scripts/scripts/test.js",
    "eject": "node node_modules/react-scripts/scripts/eject.js"
  }
chaimae
  • 21
  • 1
2

I ran into the same error since yesterday, I tried almost everything

  • Deleting node-modules and package-lock.json
  • I created a new react-app
  • I've tried even installing some stuff globally as suggested by other developers

But none of these really worked.

Finally, I've found that I had & in my project path

Cyebukayire
  • 795
  • 7
  • 14
1

In the error message it says Toubro\react[...] while leaving out your whole foldername OneDrive - Larsen & Toubro\react

You may try installing the app again in a different folder with a less complex folder name.

lotype
  • 593
  • 3
  • 8
1

I used Nikhil Kumar's answer:

$ npm build
$ npm start
Latin Warrior
  • 902
  • 11
  • 14
  • I am running into this issue. I tried the npm build command but it doesn't work: `Unknown command: "build" Did you mean this? npm run build # run the "build" package script` It's not in the list of commands: ` access, adduser, audit, bin, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor...` Did something change? @Latin Warrior – Neo Aug 20 '21 at 13:17
1

I had a similar error when executing yarn start. Removing any special signs from the path (in my case an umlaut) resolved the problem.

V.C.P.
  • 11
  • 6
1

try it yarn set version classic command then npx create-react-app your-app

https://pretagteam.com/question/createreactapp-error-cannot-find-module-reactscriptsscriptsinitjs

Rasool Aghajani
  • 340
  • 2
  • 10
1

In windows machine, I have folder with name contains capital i (which is "İ") in Turkish alphabet. This character leads to that error. While giving name to folders, avoid using characters other than English alphabet if you are a developer.

y.selimdogan
  • 599
  • 5
  • 11
1

I had this error in my React project. This error happens because your project doesn't has installed a react-script.

You can solve installing this way...

  1. npm i react-script
  2. npm start

Your app will run now! :D