I can't solve Error while running npm Start - node.js

I have an issue please. Each time I set up a react project, either with create react app or using webpack or whatever, I just get stuck at NPM start. It always returns an error. Please I am fed up with this. Can someone tell me what the issue might be?
But what bugs me the most is, I use Next.js, and each time I run Npm start on Nextjs dev server, it works fine... Please what might be the issue with my react app?
Here's the error:
C:\Users\Kelly\Desktop\My webpack react app>npm start
> webpackreactapp#1.0.0 start C:\Users\Kelly\Desktop\My webpack react app
> webpack-dev-server --mode development --open --hot
i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Users\Kelly\Desktop\My webpack react app
events.js:298
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)←[39m
←[90m at onErrorNT (internal/child_process.js:467:16)←[39m
←[90m at processTicksAndRejections (internal/process/task_queues.js:84:21)←[39m
Emitted 'error' event on ChildProcess instance at:
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)←[39m
←[90m at onErrorNT (internal/child_process.js:467:16)←[39m
←[90m at processTicksAndRejections (internal/process/task_queues.js:84:21)←[39m {
errno: ←[33m-4058←[39m,
code: ←[32m'ENOENT'←[39m,
syscall: ←[32m'spawn cmd'←[39m,
path: ←[32m'cmd'←[39m,
spawnargs: [ ←[32m'/c'←[39m, ←[32m'start'←[39m, ←[32m'""'←[39m, ←[32m'/b'←[39m, ←[32m'http://localhost:8080/'←[39m ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpackreactapp#1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpackreactapp#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Kelly\AppData\Roaming\npm-cache\_logs\2020-04-07T07_23_56_199Z-debug.log

About this question I posted here earlier, I finally found a solution to it. And I hope it would help someone. I think it's probably due to my computer's OS, the fact is I still don't know the reason my NPM start didn't work, but I found out that it was because my "react-scripts" version, which can be found in your package.json, was 3.4.1, which I think is the latest. I tried downloading the lower versions up till 2.1.8, then it worked at version 2.1.8. Though that version is way outdated, and it's probably not recommended that anyone use it, but if you still are stuck like I was, then you should try it, until you find a better solution.
Just write these commands:
npx create-react-app my-app
cd my-app
npm i --save-dev react-scripts#2.1.8
npm start
That should work and help you get your app on board.
I hope this helps someone.

It is because you have added insufficient paths in your Environmental variables.
First you can do is close the vs code,
Go to the properties of My Pc,
Click on Advanced Settings,
click on Environmental Variables,
from there you can add path clicking the path variables in the table. Add a new line to the path and copy paste the path of your system 32,
C:\Windows\System32
hope this solution works in your case
(I've been trying to fix this problem for so long this is the only solution i found that worked)

Have you restored the npm packages?
In the terminal, run:
npm install

i was also facing this same issue . after spending some time i just simply install the node.js most user version . and now issue is fixed . before it was installed latest version of node js.

Related

Unable to start project after create-react-app: Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js'

I created a small react project using npx create-react-app to work on some react tutorials but I am unable to start the react app. This i the error that I get when trying to run the project:
> test-app#0.1.0 start C:\Users\pcname\Documents\React R&D\Pluralsight\test-app
> react-scripts start
'D\Pluralsight\test-app\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\pcnmame\AppData\Roaming\npm-cache\_logs\2020-04-08T22_43_14_881Z-debug.log
I've uninstalled node, reinstalled it. Install react-scripts globally and not globally. I've replaced the start script in the package.json to be:
"start": "node node_modules/react-scripts/scripts/start.js"
and that works. I've also run react-scripts start inside the app folder and again, that works!! But I can't get it to work when I do npm start inside the app folder
Bonus: Any tutorials setting up React in Visual Studio (not vs code) without using ASP NET Core would be appreciated. I'm currently unable to set up the debugger with VS.
This error can happen after you use create-react-app in case you have some invalid character in your path.
Remove & from your path.
Change from this:
C:\Users\pcname\Documents\React R&D\Pluralsight\test-app
To this:
C:\Users\pcname\Documents\React RD\Pluralsight\test-app
It should work now!
re-running npm i solved my problem.
I had the same problem, turns out "reinstalling" npm packages gets rid of the annoying
Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js'
.
.
.
{
code: 'MODULE_NOT_FOUND',
requireStack: []
}
error message.

npm start issues with react-scripts 3.4.0

I know this question has already been asked but I can't find a solution. When I run npm start inside a react project, I always get the same logs (see below). The only solution given is to uninstall node_modules and re-do the installation. I also tried to clear the cache. Nothing worked.
Some people solved this problem upgrading to react-scripts 3.4.0 (https://github.com/facebook/create-react-app/issues/8490) but that didn't work for me. The only solution I have now is to downgrade react-scripts to version 2.1.8 by using npm install react-scripts#2.1.8. But it's not a good solution because I have to work on a framework that uses the latest version.
here are the logs :
i 「wds」: Project is running at http://192.168.43.27/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Users\fthom\Desktop\temp\my-app\public
i 「wds」: 404s will fallback to /index.html
Starting the development server...
events.js:288
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\fthom\AppData\Roaming\npm-cache\_logs\2020-02-21T10_59_13_574Z-debug.log
I finally found a solution. Add the default variables in the machines PATH:
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
Screenshot of variables location
Changing the path worked for me.
Just to add, on the above solution for those who didn't know how to change the path (same as me) and some more details.
Here is my way on how to change environment variables on Windows 10:
Open the Start Search, type in “env”, and choose “Edit the system environment variables”
Click the Environment Variables… button.
Go on system variables and under variables find PATH, mark it and click EDIT.
On the end of the list add paths - you can simply click on new or on the empty field on the end of list:
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
Remember to have the npm paths as well:
C:\Program Files\nodejs
C:\Users{yourName}\AppData\Roaming\npm
Set the environment variables as needed.
The New button adds an additional variable. ...
Dismiss all of the dialogs by choosing OK. Your changes are saved!
Restart the computer.
Now it should work!
It took me two days to resolve this issue.
Its because of the incompatibility issue of react-scripts so try installing different versions like:
This worked for me:
npm install --save react-scripts#2.1.8
This one did work for many as they claim:
npm install --save react-scripts#3.3.0
It should work as it did to me after an arduous struggle.
Sometimes on windows, I get the same error message randomly if the npm cache is somehow messed up.
Try to run
npm cache clean --force
Delete the node_modules folder and the package.lock.json file and run npm install afterward.
Open the Start Search, type in “env”, and choose “Edit the system environment
variables
Click the Environment Variables Button.
Go on system variables and under variables find PATH, mark it and click EDIT.
On the end of the list add paths - you can simply click on new or on the empty field
Go to your react app folder then go to node_modules and then go to bin folder and then copy url
Paste your url in new path

How to solve this error: "internal/modules/cjs/loader.js:638 throw err; ^"

I want to run my Vue.js using npm on localhost:8080 but they give me this error. Is there a way to solve this issue?
This error only occurs when I tried to install node_modules and package-lock.json in my Vue folder containing .babelrc, package.json and webpack.config.js. For my other Vue folders, I still can run my localhost:8080 by using the same method for all folders which is
npm install
npm run dev
The code below is the Error.
The system cannot find the path specified.
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'C:\Users\acer\Documents\VueJs\cross-env\dist\bin\cross-env.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-cli# dev: `cross-env NODE_ENV=development webpack-dev-server --open --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-cli# dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\acer\AppData\Roaming\npm-cache\_logs\2019-08-23T06_50_37_455Z-debug.log
Before you go uninstalling everything, try closing the terminal and trying again in a new Terminal instance
I had a similar issue which I solved by noticing that when I followed the advice here: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1056#issuecomment-699456515
and proceeded to run npm run build which is what was giving me that error, it would work inside of the newly created project with vue create <project-name>.
I had my code in a repository so I recloned it, copied the node_modules folder into my working directory and then ran it again and it worked.
If you want to update NodeJS and it is not achieving, try the nvm instead.
I was trying in my Ubuntu and I used curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
If there isn't the file .bashrc, try execute: source ~/.bashrc
And then: nvm list-remote
Finally, install: nvm install v13.6.0 (That's today version - 2021).
I came across this issue; This issue is a result to your external hard-drive been corrupt or affected by virus. Format your external drive or better still create your application on your computer's drive instead of external drive.

Problem with npm start (error : spawn cmd ENOENT)

I have a problem with my application. Because before when I created an application it worked, but now, it shows me this error and I do not know why and the things I have to do to fix it.
Do you have any idea to help me ? (This is a reactJS app).
I checked some stackoverflow topics but everywhere I checked, it was not really an answer that worked.
events.js:180
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs: [ '/c', 'start', '""', '/b', 'http://localhost:3000/' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fix-react-module#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fix-react-module#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lucas\AppData\Roaming\npm-cache\_logs\2019-07-16T09_33_39_111Z-debug.log
Add C:\Windows\System32 to the global PATH environment variable.
Solution 1
Set your environment variable to C:\Windows\System32 . This works for me.
Sets System variable
Solution 2
If the first one doesn't work follow the 2nd steps. Navigate to your project folder and type this command >>>
rm -rf node_modules
rm package-lock.json
rm yarn.lock
npm cache clear --force
npm install
Solution 3
Downgrade react-scripts in package.json file
I had the same problem after I tried to install Mongo DB. I found out that this problem only exists with react-scripts#3.0.0. Try to reinstall your npm with a different react script version. Simply go to your folder in command and reinstall like this:
npm install react-scripts#2.1.8
npm start
After that the app worked for me again.
For all those Who've come to this problem from react scripts not starting. The solution is
Go to search bar and write environment variables. You should see an option to called edit system environment variables or something similar.
Under the Advanced section there is a enivronment variable button. click it.
After that you will see an option named path click on it.
click add button and add following directory C:\Windows\System32.
close down your editor and restart your command terminal.
Problem should be resolved now 😁
If someone hits this coming from Angular 2+, remove the --open from ng serve or run without this option.

Having a hard time getting the Angular CLI server to start

I'm sure this isn't the first time you've run into this issue. I've researched over google, youtube, and stackoverflow on this issue, and it seems like this is an isolated incident. I don't know if it's an issue with versions, but I have been taking the Pluralsight course on Angular with Deborah K. I downloaded her Github version of the boilerplate starting files from https://github.com/DEborahK/Angular-GEttingStarted
I followed the course and installed the dependences from the package.json file using the integrated terminal. When I tried to run the script npm start which translates into ng serve -o I get this error message:
apm#0.0.0 start /Users/mateo/Desktop/projects/angular
ng serve -o
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (/Users/mateo/Desktop/projects/angular/node_modules/#angular/cli/tasks/serve.js:21:63)
at check_port_1.checkPort.then.port (/Users/mateo/Desktop/projects/angular/node_modules/#angular/cli/commands/serve.js:110:26)
at
at process._tickCallback (internal/process/next_tick.js:118:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apm#0.0.0 start: ng serve -o
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the apm#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mateo/.npm/_logs/2018-03-26T22_16_46_516Z-debug.log
Sandys-MacBook-Pro:angular mateo$
Is there a best practice way to troubleshoot these kind of issues? Is there a better way to run these scripts or should I use a sandbox VMware linux install to run these fresh instead of running off my Macbook? Any help is appreciated! Thank you!
I was able to fix this issue by deleting all of the node_modules and re-installing the AngularCLI from scratch off of the Angular website.

Resources