28

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.

5
  • try npm i again Commented Mar 29, 2020 at 9:43
  • Did but same error afterwards. Commented Mar 29, 2020 at 9:51
  • 6
    If you have an & in your project's path you will run into this issue, at least on Windows it -->> i had the same issue and it got resolved after Changing the path Commented Apr 4, 2021 at 10:14
  • You have a space between your first and last name in the path to your project. I am not sure this is going to work too well. Commented Jun 28, 2021 at 3:06
  • I wish I knew this earlier: consider whether your project has more than one level of node_modules: stackoverflow.com/a/70793086/470749 Commented Jan 20, 2022 at 20:39

18 Answers 18

76

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This is what caused the error for me. Had an "&" symbol as my directory name. Unfortunate.
This is actually what's causing the problem. Anyone knows why?
Thanks a lot and removing "&" from project directory solves the error
Thanx bro, yes it worked for me, I just removed '&' from the file path ( in window 11 )
15

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.

Comments

10

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.

1 Comment

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.
6

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

react-scripts build

1 Comment

As weird as this may seem, doing an npm build first and then an npm start, worked for me. $ npm build $ npm start
4

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

1 Comment

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.
3

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"
  }

Comments

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.

Comments

3

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

Comments

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.

9 Comments

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.
In .npmrc file do you have the registry url assigned? like this registry=http://registry.npmjs.org/.
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.
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.
I didn't find .npmrc file anywhere in myapp folder and its subfolder. could you please tell me where to find it.
|
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 Comment

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.
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

Comments

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.

Comments

1

I used Nikhil Kumar's answer:

$ npm build
$ npm start

1 Comment

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
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.

Comments

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

Comments

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.

Comments

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

Comments

0

I have faced similar issue. Problem seems to be

"C:\Users\Lovepreet Singh\react-scripts\bin\react-scripts.js"

and try to remove spaces of your folders and try "npm start"

"C:\Users\Lovepreet_Singh" (Use "_" or "-" to remove spaces of folder name)

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.