363

I'm trying to learn react, so I have this sample code for the full-stack react voting app, and I am trying to get it to work but after running npm install followed by npm start I receive the following error when I run npm start can anyone help me with this issue:

npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "server"
npm ERR! node v7.5.0
npm ERR! npm  v4.3.0
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! voting_app@1.1.0 server: `live-server --public --    
host=localhost --port=3000 --middleware=./disable-browser-cache.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the voting_app@1.1.0 server script 'live-server --
public --host=localhost --port=3000 --middleware=./disable-browser- 
cache.js'.
npm ERR! Make sure you have the latest version of node.js and npm  
installed.
npm ERR! If you do, this is most likely a problem with the voting_app  
package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     live-server --public --host=localhost --port=3000 --  
middleware=./disable-browser-cache.js
npm ERR! You can get information on how to open an issue for this  
project with:
npm ERR!     npm bugs voting_app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls voting_app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ItsMeMrLi/.npm/_logs/2017-02-17T22_48_03_581Z-
debug.log

npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.5.0
npm ERR! npm  v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! voting_app@1.1.0 start: `npm run server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the voting_app@1.1.0 start script 'npm run server'.
npm ERR! Make sure you have the latest version of node.js and npm 
installed.
npm ERR! If you do, this is most likely a problem with the voting_app    
package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run server

npm ERR! You can get information on how to open an issue for this   
project with:
npm ERR!     npm bugs voting_app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls voting_app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ItsMeMrLi/.npm/_logs/2017-02-17T22_48_03_655Z-
debug.log

Here is my package.json:

{
  "name": "voting_app",
  "version": "1.1.0",
  "author": "Fullstack.io",
  "scripts": {
    "go": "open http://localhost:3000; npm run server",
    "e2e": "nightwatch",
    "test": "./node_modules/.bin/concurrently -k 'npm run server' 'npm  
run e2e'",
    "start": "npm run server",
    "server": "live-server public --host=localhost --port=3000 --  
middleware=./disable-browser-cache.js"
  },
  "private": true,
  "devDependencies": {
  "concurrently": "2.2.0",
  "live-server": "git://github.com/acco/live-server.git"
},
  "dependencies": {
  "semantic-ui": "git://github.com/Semantic-Org/Semantic-
  UI.git#27d58a01793b66318478fbc5b6676804d22d065d"
  }
}

And finally my log file:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@4.3.0
3 info using node@v7.5.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle voting_app@1.1.0~prestart: voting_app@1.1.0
6 silly lifecycle voting_app@1.1.0~prestart: no script for prestart, continuing
7 info lifecycle voting_app@1.1.0~start: voting_app@1.1.0
8 verbose lifecycle voting_app@1.1.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle voting_app@1.1.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/ItsMeMrLi/.rvm/gems/ruby-2.3.1/bin:/Users/ItsMeMrLi/.rvm/gems/ruby-2.3.1@global/bin:/Users/ItsMeMrLi/.rvm/rubies/ruby-2.3.1/bin:/Users/ItsMeMrLi/.cargo/bin:/usr/local/Cellar/smlnj/110.74/libexec/bin:/usr/local/bin:/Users/ItsMeMrLi/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Downloads/geckodriver:/usr/local/bin:/Users/ItsMeMrLi/.rvm/bin
10 verbose lifecycle voting_app@1.1.0~start: CWD: /Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app
11 silly lifecycle voting_app@1.1.0~start: Args: [ '-c', 'npm run server' ]
12 silly lifecycle voting_app@1.1.0~start: Returned: code: 1  signal: null
13 info lifecycle voting_app@1.1.0~start: Failed to exec start script
14 verbose stack Error: voting_app@1.1.0 start: `npm run server`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:192:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:192:7)
14 verbose stack     at maybeClose (internal/child_process.js:890:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid voting_app@1.1.0
16 verbose cwd /Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app
17 error Darwin 16.4.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 error node v7.5.0
20 error npm  v4.3.0
21 error code ELIFECYCLE
22 error errno 1
23 error voting_app@1.1.0 start: `npm run server`
23 error Exit status 1
24 error Failed at the voting_app@1.1.0 start script 'npm run server'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the voting_app package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     npm run server
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs voting_app
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls voting_app
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]
Bharathvaj Ganesan
  • 2,562
  • 1
  • 14
  • 30
  • 2
    Make sure you also have space left on the drive. – Mircea Jul 25 '18 at 12:44
  • If you were like me you were following the FullStack React book. When you posted this question it is very likely you omitted the vital part of the message preceding what you posted. See here https://stackoverflow.com/a/65399700/495157 (relative path of disable-browser-cache.js). `./ ` -> `../..` https://github.com/tapio/live-server/issues/245 – JGFMK Dec 21 '20 at 20:59

40 Answers40

419

Step 1: $ npm cache clean --force

Step 2: Delete node_modules by $ rm -rf node_modules (rmdir /S /Q node_modules in windows) folder or delete it manually by going into the directory and right-click > delete / move to trash. If are not updating your packages you can delete the package-lock.json file too.

Step 3: npm install

To start again, $ npm start

This worked for me. Hopes it works for you too.

PS: Still if it is there, kindly check the error it is displaying in red and act accordingly. This error is specific to node.js environment. Happy Coding!!

Packman
  • 37
  • 5
Prakhar Mittal
  • 4,945
  • 1
  • 9
  • 28
  • 28
    heads up be careful when using rm -rf – Suhayb Nov 25 '18 at 17:56
  • 31
    For Step 2 in Windows you can do `rd /s /q "node_modules"`in **cmd** or `rm -r "node_modules"` in **PowerShell** [Source](https://stackoverflow.com/questions/97875/rm-rf-equivalent-for-windows) – Travis Heeter Dec 05 '18 at 13:14
  • In my case deleting node_modules helped, but this folder that was one level up to the project. npm cache clean --force was causing weird behavior instead and was misleading. Before I deleted this directory I also deleted local repository for this project and cloned it again, not sure if it was helping though since the action I described solved the situation finally. – Lukasz May 29 '19 at 10:31
  • If that doesn't work, you can always command another npx create-react-app spare, and copy node_modules over to project appropriately.(USER FRIENDLY WAY) – Goku Oct 22 '20 at 07:06
  • It's worth mentioning that in many instances it is not recommended to delete package-lock.json because of dependency version rollbacks. See a similar answer by skyboyer to a similar question. Using the above advice has created a considerable mess for me, thank you for answering in any case! https://stackoverflow.com/questions/54124033/deleting-package-lock-json-to-resolve-conflicts-quickly/54127283 – Hunter Wiley Feb 11 '21 at 05:31
  • 1
    for step 2, I think you can use npm ci – vuquanghoang Feb 18 '21 at 10:10
  • `npm run dev` worked for me in step 4 – Adith May 22 '21 at 10:15
113

Cleaning Cache and Node_module are not enough. Follow this steps:

  • npm cache clean --force
  • delete node_modules folder
  • delete package-lock.json file
  • npm install

It works for me like this.

Ankit Jayaswal
  • 5,031
  • 3
  • 13
  • 34
Babak Habibi
  • 1,294
  • 1
  • 6
  • 13
  • 19
    Fixed for me using `npm cache verify` instead of deleting the entire cache. – Jared Oct 07 '18 at 02:18
  • 3
    I think the most important thing is delete the package-lock.json file, before try this, I've tried many ways all cannot fix the error. – BobGao Feb 06 '19 at 08:41
  • 20
    The fact that you can fix ANYTHING by simply deleting an autogenerated build artifact is everything that is wrong with the JS universe... If it wasn't for this stackoverflow entry I would have been S.O.L. here as there was no actionable error I could discern in the build log! – pmarreck Jun 21 '19 at 19:26
  • Most imp is deleting package-lock.json – Yusuf Jun 27 '20 at 15:51
  • If the error still exist after the above solutions, increase the no of listeners. https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers – shamila Sep 17 '20 at 09:36
  • Thanks, it works for me!! – DenisDaniel707 Jan 12 '21 at 16:43
  • this worked!!!! – fewaf Apr 30 '21 at 18:32
32

first i ran:

npm run clean

(even though it came with errors)

Then i deleted the node_modules folder and ran

npm install

This seems to have solved the problem.

alepuzio
  • 1,350
  • 2
  • 28
  • 36
29

I resolve this error running following code

npm cache clean

then delete node_modules directory from my project structure manually or with following command

rm -rf node_modules

After That install dependencies again using

npm install
Sajjan Singh
  • 2,399
  • 2
  • 22
  • 30
Uditha Prasad
  • 535
  • 4
  • 12
  • 7
    It would really help if you can elaborate the answer for the beginners like me. Brevity is good but doesn't help always. Thank you. – imsrgadich Jun 04 '17 at 07:58
  • 1
    ``npm run clean`` is no command. But, still you idea worked. I deleted and reinstalled..and booom... it started working.. thanks – Tarunn Jun 20 '17 at 09:49
  • Just the last instruction "npm install" worked in my similar case. – ged Jan 17 '20 at 07:05
  • had that problem with Nuxt.js after copy / paste my code from desktop to server. not it works thanks – Ifaruki Jul 16 '20 at 21:16
  • npm cache clean then npm cache verify then rm -rf node_modules then npm install – Winnie Nyambura May 03 '21 at 20:01
23

I was getting similar error messages on a 16.04 Ubuntu instance with DigitalOcean while running npm run build on an app made with create-react-app (link). I upgraded the instance from 512MB RAM to 1GB ($5/mo to $10/mo) and then the script was able to run.

I post this here to point out that you may get this error due to resource limitations, which I didn't really see explained elsewhere on issue pages and SO answers. And nothing I saw in the error logs pointed me in this direction.

Keith Axline
  • 331
  • 2
  • 3
  • You are completely right ! Nothing point me in this direction too, and it was a bug due to resource limitations... Ty – Kubadev Jul 31 '19 at 14:31
  • Yeah I was getting similar issue compiling Laravel-mix on EC2 t3a.nano instance. Seems to be lack of memory. Resolved on a larger instance. – mCpXZKq3ruqgFXrvvAWRj9cYxk8RLX May 16 '20 at 22:08
  • Before you do this, you might want to try to reboot your server first: https://www.digitalocean.com/community/questions/how-to-reboot-droplet-through-the-command-line-restart-apache-server For me that was sufficient already :) – Jumelet Nov 20 '20 at 00:20
22

Change access in node_modules directory

chmod -R a+rwx ./node_modules 
Taher
  • 10,838
  • 2
  • 27
  • 41
12

Delete node_modules and package-lock.json, and then run npm install. It worked perfectly here(run command below inside project root):

rm -rf node_modules && rm ./package-lock.json && npm install
Eddie Teixeira
  • 322
  • 2
  • 9
11

This solution is for Windows users.

You can open the node.js installer and give the installer some time to compute space requirements and then click next and click remove. This will remove node.js from your computer and again reopen the installer and install it in this path - C:\Windows\System32

or

Cleaning Cache and Node_module will work. Follow this steps:

  • npm cache clean --force
  • delete node_modules folder
  • delete package-lock.json file
  • npm install
Jesvin Vijesh S
  • 439
  • 4
  • 22
9

Faced this exact problem,

for me it worked by deleting package-lock.json and re run npm install

if it doesn't resolve try

  1. delete package-lock.json
  2. npm cache clean --force
  3. npm install
  4. npm start
NuOne
  • 4,218
  • 1
  • 27
  • 39
7

workaround: Remove the lock file.

rm .\package-lock.json

source: https://github.com/mapbox/node-pre-gyp/issues/298 (floriantraber)

enam
  • 952
  • 11
  • 11
7

React Application: For me the issue was that after running npm install had some errors.

I've went with the recommendation npm audit fix. This operation broke my package.json and package-lock.json (changed version of packages and and structure of .json).

THE FIX WAS:

  • Delete node_modules
  • Run npm install
  • npm start

Hope this will be helpfull for someone.

Calin Vlasin
  • 995
  • 9
  • 17
6

This solution fixed the error in Win10.

Please install globally npm install -g node-pre-gyp

monkrus
  • 740
  • 17
  • 20
6

i tried to solve this problem with this way

rm -rf node_modules && rm ./package-lock.json && npm install

But for me its not work. I just restart my machine and its working perfectly.
Am Linux user ,Machine HP.

Ripon Uddin
  • 482
  • 2
  • 10
  • 21
5
npm install --unsafe-perm

worked for me. See https://docs.npmjs.com/. The --unsafe-perm parameter lets you run the scripts from the package instalation as root. The problem in my case was that some depandencies failed to install.

SePeF
  • 317
  • 3
  • 7
4

I'm using ubuntu 18.04 LTS release and I faced the same problem I tried to clean cache as above suggestions but it didn't work for me. However, I found another solution.

echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches

npm start

I run this command and it started to work

Otabek Butcher
  • 289
  • 5
  • 7
3

Try to reinstall the cli package globally. In my case, I was trying to test a Vue.js tutorial when I get the same error message. The other thing I did was run the vue command again but this time using webpack-simple and that is why I am not sure wich one solved the problem but now it is working.

eryx
  • 41
  • 2
3

Check for port availability as well if you encounter below message :

Error: listen EACCES 127.0.0.1:8080

at Object._errnoException (util.js:999:13)
at _exceptionWithHostPort (util.js:1020:20)
at Server.setupListenHandle [as _listen2] (net.js:1362:19)
at listenInCluster (net.js:1420:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1535:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:102:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
3

Usually killall node command fixes mine.

Diana
  • 420
  • 2
  • 9
3

I was getting this npm ERR! code ELIFECYCLE error while running a build. Clearing the cache and removing the package-lock.json files did not fix it.

In my case there was an Angular build running on a Docker image that was causing this. The root cause turned out to be running the build on Docker in MacOS, which runs the Docker inside a Linux VM, and has by default 2GB memory allocated.

Giving Docker more memory fixed this issue for me. Have to say, the error message could have been quite a bit more clear..

A helpful answer for me was Call retries were exceeded exception while ng build

kg_sYy
  • 869
  • 7
  • 18
2

I've been bothered by this issue for a long time. For me, the version of node was the problem.

My npm and node were 6.1.0 and 8.11.3, respectively. However, I didn't realize that I had updated my node accidentally to 12.*.*.

It then began to install GCX stuff whenever npm i, which was unnecessary before.

I downgraded my node to 8 and it worked!

Michael Piefel
  • 14,444
  • 5
  • 65
  • 95
W.H Lee
  • 167
  • 2
  • 8
2

Its weird but it works for me

Go to

control panel -->System and Security--> System --> Advanced System Security--> Environment Variables

In Environment Variable popup you will edit the user variable PATH and add "C:\Windows\System32" value as semicolon separated to the existing value.

Not but not least restart the Machine.

enter image description here

Joee
  • 1,104
  • 11
  • 15
2

The port is probably being used by another application, try listing and see if it's your application:

lsof -i:8080

You can kill the process of this port:

lsof -ti:8080 | xargs kill

Ivan Ferrer
  • 397
  • 4
  • 9
2

I recommend you update your node version to the latest node version recommended by your application or for short update your node version. I encountered this same problem using node version 11.1 but my application was recommending atleast version 10.x.x or 12.x.x I tried all the suggested reply on this thread but non seemed to work for me untill only when i updated my node version to the recommended latest version .i.e. version 12.16.3 then my application ran. enter image description here

Virtu_Acad
  • 121
  • 5
1

Resolved like this:

# chown -R <user>: node_modules
Gilles Quenot
  • 143,367
  • 32
  • 199
  • 195
1

Make sure to use the latest npm version while installing packages using npm.

While installing JavaScript, mention the latest version of NodeJS. For example, while installing JavaScript using devtools, use the below code:

devtools i --javascript nodejs:10.15.1

This will download and install the mentioned NodeJS version. This worked for me.

simran agarwal
  • 301
  • 1
  • 6
1

I did follow steps, it works:

1.

npm cache clean --force
  1. remove the package-lock.json file

  2. restart my WebStorm

aircraft
  • 16,211
  • 16
  • 74
  • 135
1

A possibly unexpected cause: you use Create React App with some warnings left unfixed, and the project fails on CI (e.g. GitLab CI/CD):

Treating warnings as errors because process.env.CI = true.
[ ... some warnings here ...]
npm ERR! code ELIFECYCLE
npm ERR! errno 1

Solution: fix yo' warnings!

Alternative: use CI=false npm run build

See CRA issue #3657

(Ashamed to admit that it just happened to me; did not see it until a colleague pointed it out. Thanks Pascal!)

Hugues M.
  • 17,453
  • 5
  • 27
  • 56
1

I was issuing the npm start command with the folder of the project opened at Sublime Text. Closing ST and restarting the server did the work for me.

Marco Floriano
  • 160
  • 3
  • 13
1

My solution:

I was missing config.env properties because I was developing on a new machine, and of course I keep my config files out of my repo.

If you are using a different machine than usual, make sure that you include any config files that are not present in the repo that gets cloned.

SauerTrout
  • 311
  • 1
  • 4
  • 13
0

In my case, I had checked out a different branch with a new library on it. I fixed my issue by only running npm install without doing anything else. I was confused why I was getting ELIFECYCLE error when the port was not being used, but it must have been because I did not have the library installed. So, you might not have to delete node_modules to fix the issue.

Rock Lee
  • 7,370
  • 8
  • 47
  • 82
0

I am using react-create-app in Windows 10, on February 2nd, 2019 with latest NodeJS 11.9.0 and npm 6.7.0 (When you install NodeJS, the npm is existing). I think case of node packages are corrupted is rarely, the main cause permission.

At the beginning, I put project directory at Desktop, it is belong to C:\ driver. I move to another directory of another driver. Therefore, I remove "file permission" concern. Every work well and simple.

cd /d D:\
mkdir temp20190202
npx create-react-app my-app
cd my-app
npm start

It is ok, not put project folder in a directory of C:\ (or other driver what contains Windows Operating system).

Do Nhu Vy
  • 33,131
  • 37
  • 143
  • 202
0

I had the same issue with Angular 7. Just went through the following steps and error was solved.

1). Delete your node_modules folder and package-lock.json file.

2). Run npm install command.

3). Run npm audit fix command.

Chamila Maddumage
  • 1,956
  • 1
  • 17
  • 32
0

This had nothing to do with NPM packages for me. My Vuepress project was using a custom host name. Omitting this got things working again.

Mark Notton
  • 4,482
  • 4
  • 17
  • 23
0

This solved me on ubuntu 16

1) Update npm and node to latest version . 2) Restart System 3) Remove node_modules and again npm i & npm start

Vyas Reddy
  • 923
  • 1
  • 11
  • 19
0

My situation called for removing webpack folder globally, then deleting project node_modules folder, package-lock.json and running npm install, npm start

Kamau
  • 43
  • 1
  • 6
0

The other answers did not solve the problem for my case. This works for me:

  • Try deleting your build output.
  • For me, that means deleting general.dll.js

Additional Details

  • Windows 10 64bit dev machine
  • NPM Start running webpack generating a build file: general.dll.js
  • If I get the ELIFECYCLE error upon "NPM Start" it is often after I have already successfully executed "NPM Start" but then stopped it, only to start "NPM Start" again.
  • I noticed that general.dll.js showed up in some of the hard-to-understand logs
Brian Webster
  • 27,545
  • 47
  • 143
  • 218
0

Well! I got this error while writing react code many times, most of the time it is because of the following two

  1. When you imported something from the wrong library, for example
   import {Button} from "bootstrap"; //wrong one
   import {Button} from 'react-bootstrap';//the correct one
  1. When you imported two of the same name elements from different libraries
   import {Text} from 'react-native';
   import {Text} from 'native-base';

if this is not your mistake then you should delete all node modules and install again or start a new project and work on it!.

ayyappa
  • 44
  • 5
-2

please upgrade your RAM size of the server location and try it. it'll work sure.

mafei
  • 479
  • 3
  • 15
-3

run the command as superuser:

sudo npm x-command
amxa
  • 699
  • 7
  • 6
  • 3
    This answer doesn't explain why this command would benefit the use case. Could you please elaborate on the reasons why this would be a valid solution? – Arnaud Leymet Feb 25 '18 at 06:06
-3

I Resolved this error, please enter following commands

npm install -g express-generator
express --view=hbs /tmp/foo && cd /tmp/foo
npm install
npm start
Rinav
  • 2,169
  • 7
  • 29
  • 48
Siva
  • 17
  • 4