node-pre-gyp install error on npm install - javascript

I was trying to follow the react in action book. - book's project repo
But on doing npm install on Ubuntu, I am getting
npm ERR! errno 1
npm ERR! grpc#1.7.3 install: `node-pre-gyp install --fallback-to-build --library=static_library`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the grpc#1.7.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.`
I have also tried to update my node and npm version and then npm install but it's still not working .
Help me to fix this irritating error .
Edit:
I have tried to fix this using almost 10 answers from SO as well as github but none of them works and also some of the answer is for windows or mac and not for ubuntu. I have tried the answers to these questions too.

This issue just wasted my day. I went through a lot of solutions like installing node-pre-gyp, uninstall and reinstall node and npm, cleared the cache and node modules and reinstall installed the dependency. But none of the solutions worked.
At last, I fixed it by downgrading the npm version from v10.xx to v9.9.0. Steps that I followed (for mac):
Open terminal and type sudo npm install -g n
Once step 1 done, type n 9.9.0 to downgrade the npm version
Hope it helps :)

Related

Error: You are running `create-react-app` 5.0.0, which is behind the latest release (5.0.1)

As the title says, I cannot run create-react-app.
You are running `create-react-app` 5.0.0, which is behind the latest release (5.0.1).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
Doing this does not change the error. npm uninstall -g create-react-app
I entered this command to try it out and got a message that the tar was out of date.
npm install -g create-react-app
npm WARN deprecated tar#2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm ERR! code EEXIST
npm ERR! path /opt/homebrew/bin/create-react-app
npm ERR! EEXIST: file already exists
npm ERR! File exists: /opt/homebrew/bin/create-react-app
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
https://www.npmjs.com/package/tar
I ran the command with this reference.
However, the tar was not updated.
I have already tried all the published solutions, but they don't work. Can someone please help me? Please.
I tried clearing the cache but could not solve the problem.
npx clear-npx-cache
Need to install the following packages:
clear-npx-cache
Ok to proceed? (y) y
I was able to successfully run the following command by specifying the version each time, but it is a hassle and I want to be able to run it normally.
npx create-react-app#latest my-app
The "fish" shell I am currently using is node v18.0.0, so I downgraded to v16.15.0 and it works fine.
fisher install jorgebucaran/nvm.fish
nvm install v16
I had forgotten to lower the node version in fish because it had been working fine with zsh.

Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"

When I was trying to create a new react app using npx create-react-app example_app, I get this error
[Your cache folder contains root-owned files, due to a bug in previous
versions of npm which has since been addressed sudo chown -R 0:0
"/root/.npm"]
I even tried to re-install create-react-app again using npm i create-react-app, it is giving the same kind of
error.
I assume after searching about it that it is due to some permissions issue. My current user doesn't have permission to /home/shubham/.npm where shubham is my username, but I am not so sure about this.
I have tried to solve this error using chown command as
sudo chown -R <username>:<groupname> /home/shubham/.npm"
where <username> is Shubham and <groupame> is 1000, but it is still not working.
Request people to help me out.
If you need any more information, let me know.
This worked for me:
sudo npm cache clean --force
This is what helped me after going through the above answers. I hope it helps someone else too. After re-reading the npm error prompt, I adjusted the provided command to include the .npm path given in the error message. Below is a copy of my original error messages.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/vagrant/.npm-global/lib/node_modules
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 900:900 "/home/vagrant/.npm"
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2020-07-09T16_43_35_046Z-debug.log
[ExecStack] Exit code 243 Time 01:03
[error] Executing target-hook frontend-reqs failed.
[error] Command source:build:frontend-reqs exited with code 1.
Instead of using sudo chown -R 900:900 "/home/vagrant/.npm", I used sudo chown -R 900:900 "/home/vagrant/.npm-global". After that, I was able to use the previous command that caused the error with no issues.
Set the npm_config_cache environment variable
in linux
export npm_config_cache=/path/to/cache
in windows
set npm_config_cache=/path/to/cache
Try sudo chown -R 1000:1000 "/home/shubham/.npm"
I had to do both the root folder and the root/.npm
sudo chown -R 1001:1001 "/root"
sudo chown -R 1001:1001 "/root/.npm"
If you are using CI and share the CI slave with other teams, maybe not possible to sudo chown -R {group}:{user} "~/.npm" (i.e.: using Github Enterprise with Github Actions on shared runners
I add
# use local cache to work-around 'npm ERR! path ~/.npm/_locks/staging-xxx.lock' in GHA
cache=./npm-cache
into my .npmrc in the repo to solve the issue by using local npm cache dir
I had the same issue and several others while trying to update my npm packages. I will be honest I do not have enough knowledge of package handlers or why this fixed my situation, but I believe my version of npm and npx were causing the issues. I had errors immediately trying to install npx, node and create-react-app with my old and out of date version of npm.
I could not run npm install npx -g without --force. Once I did that I also ran npm install npm -g --force. After this I could already tell things were different.
After npm and npx were completely overwritten, I ran npm install node -g and npm install create-react-app -g without any weird problems. I created a new react app and started it error free.
(I also ran the cache command before all of this. sudo npm cache clean --force which I am unsure if it helped).
I was getting this while running npx #11ty/eleventy as root:
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1000:1000 "/root/.npm"
No, /root/.npm is supposed to be owned by root. It's not at all due to a bug in a previous version of npm. And yes, the root user has permission to read and write that directory. So this is a bug in the current version of npm that prevents building the project as root.
Of course following the nonsensical instructions to change the root homedir's ownership does not work.
In my case, I was running it as root as part of a build script that needs root for an rsync to complete:
#!/bin/bash -eu
# mybuildscript
npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
So my workaround was to run that single line as an unprivileged user using sudo:
#!/bin/bash -eu
# mybuildscript
sudo -u ki9 npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
I am using npm version 7.5.2. Hopefully this will be addressed in a future version of npm.
I also tried all of the above steps on my MAC Catalina, but didn't resolve my issue. These steps resolved my problem:
npm update
npx --ignore-existing create-react-app my-app
Thanks to this comment
This will work:
sudo chown -R 1000:1000 "~/.npm"
Neither force-cleaning the cache nor using chown worked for me, but deleting the folder did work and fixed the issue.
My error was:
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 501:20 "/Users/aw/.npm"
The fix was to permanently erase the .npm folder in question, which I did using rm -rf:
sudo rm -rf /Users/aw/.npm
(Mandatory warning: this is a dangerous command if you typo it.)
I encountered the same issue and the problem with mine was that I was running an older version of npm. After updating npm and removing the .npmrc file, it worked just fine.
npm install -g npm#latest
rm .npmrc
Be careful before deleting the .npmrc file, take a backup as it will reset your npm configuration.
I fixed mine by running:
sudo npm cache clean --force
followed by removing the root owned files.
first, to view the file owners and group:
cd /Users/username/
ls -la
You have to check the owner of .npm, changed to non-root user:
sudo chown -R username:group "/Users/username/.npm"
or for global .npm-global
sudo chown -R username:group "/Users/username/.npm-global"
replace keyword: username/group accordingly
It helped me:
Remove and install npm again
It work for me now!
What I did? (I'm not saying it's the best way to fix this but i'ts working for me. I'm still looking for the best explications for this issue)
sudo rm -Rf /home/[YOUR_USER_NAME]/.npm-global/lib/node_modules/
and run your command again.
My explication is that it seems like something is corrupted in the node_modules's folder.
As it's not risky to delete it I did it and it works now.
Try sudo npx create-react-app example_app or in my case sudo npm install #vue/cli
I tried everything else here, but in the end realised that it might just be the command that I was running was not able to escalate the correct permissions.
Find error in your log file:
verbose Error: EACCES: permission denied, mkdir '/Users/xxx/.tnpm_tmp/npm-52731-e91f6671'
Use that error in your condition.
sudo chown -R 502:20 "/Users/XXX/.tnpm_tmp"
I solve the problem with the following commands
Install dependence > npm install create-react-app
run > create-react-app project_name
happy hack!!
Try to create your react app using yarn package manager.

npm ERR! Cannot find module './access-error.js'

Anything I try to do with NPM, I end up with npm ERR! Cannot find module './access-error.js'. Help!
I first noticed it when trying to install vue-chartjs. I ran npm install vue-chartjs chart.js --save like the docs said to do and got the error:
code/premium-poker-tools [master●] » npm install vue-chartjs chart.js --save
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './access-error.js'
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/adamzerner/.npm/_logs/2019-03-12T23_56_46_114Z-debug.log
Then I tried installing chart.js and vue-chartjs individually, but it gives me the same error.
Then I googled the issue. I tried:
rm -rf node_modules
npm install
and it didn't work.
I tried reinstalling NPM and it didn't work. I tried removing NPM via sudo npm uninstall npm -g and then planning on reinstalling it after, and it didn't work. Everything I do gives me the npm ERR! Cannot find module './access-error.js' error.
This problem sounds very similar to one I had a few weeks ago.
What worked for me was removing Node.js from my Mac and reinstalling it, because installing Node.js installs npm as well.
Command used to remove Node.js: sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
Then just reinstall Node.js and everything should work again!
Hope this helps!
Ran into the same issue. Was using Node v8.11.4. Switched to Node v8.9.4 and it started working again...
Using NVM, I did the following:
nvm ls
nvm install <different version>
nvm alias default <different version>
Best guess is that it wasn't 8.11 specifically, but something with my particular installation was messed up and using a fresh install fixed it.
Not very satisfying. ¯\_(ツ)_/¯
I faced the same problem. Found that the node version is different.
Try the following:
1. nvm ls
2. nvm use <latest version available>
Now baam .. it works.

Node error Cannot read property 'resolve' of undefined

I am using reactjs and am unable to install any packages using npm install. The error message I'm getting is :
npm ERR! Cannot read property 'resolve' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /home/stash/.npm/_logs/2019-03-11T10_07_30_264Z-debug.log
When I do npm install -verbose:
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'install',
npm verb cli '-verbose' ]
npm info using npm#6.7.0
npm info using node#v11.10.1
npm verb npm-session 869376d36eca27b5
npm info lifecycle proj-lite#1.0.0-alpha.6~preinstall: proj-lite#1.0.0-alpha.6
npm timing stage:loadCurrentTree Completed in 22ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1231ms
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 2661ms
npm verb stack TypeError: Cannot read property 'resolve' of undefined
npm verb stack at regFetch (/usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js:76:23)
npm verb stack at fetchPackument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:42:10)
npm verb stack at packument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:20:10)
npm verb stack at getManifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:22:10)
npm verb stack at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:13:10)
npm verb stack at Object.manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:17:12)
npm verb stack at Object.Fetcher#manifest [as manifest] (/usr/local/lib/node_modules/npm/node_modules/genfun/lib/genfun.js:15:38)
npm verb stack at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:23:18)
npm verb stack at pinflight (/usr/local/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
npm verb stack at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
npm verb stack at Promise._execute (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/debuggability.js:313:9)
npm verb stack at Promise._resolveFromExecutor (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:483:18)
npm verb stack at new Promise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:79:10)
npm verb stack at _inflight (/usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
npm verb stack at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14
npm verb stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb cwd /var/www/html/lite-proj/lite-proj
npm verb Linux 4.4.0-142-generic
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-verbose"
npm verb node v11.10.1
npm verb npm v6.7.0
npm ERR! Cannot read property 'resolve' of undefined
npm verb exit [ 1, true ]
npm timing npm Completed in 3862ms
npm ERR! A complete log of this run can be found in:
npm ERR! /home/stash/.npm/_logs/2019-03-11T10_12_15_921Z-debug.log
I am not even able to uninstall npm and reinstall it as I am getting the same error when I try to uninstall. What is the issue here and how do I fix it?
I got into this situation with an old version of the n node version switcher (~v2), having switched onto Node v12. I was able to fix it by switching to a much older version of Node it had installed using n, v8 worked for me, and then upgrade the version switcher with sudo npm install -g n.
From there I could switch to any version of node and use npm again.
The reason for the error was probably conflicting global packages and node versions. I uninstalled node and npm and then reinstalled them.
To remove nodejs and associated packages (like npm):
sudo apt-get purge --auto-remove nodejs
Nodejs and npm will leave files in the system which may cause issues during reinstallation. I had to remove them as well.
Although it is a bad practice to remove packages manually (it may cause problems with the package manager), it helped my case. This answer shows how to remove nodejs and related files manually.
To reinstall them:
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
So I have recently faced a very similar problem when I was trying to run a react project in my Windows 10 x64 PC. Although I installed Node.js v12.13.0 (+ npm v6.12.0) x64; I couldn't execute npm install command, as it would give me this same error (Cannot read property 'resolve' of undefined).
Then according to this comment, I uninstalled the x64 version of Node.js and then installed the x86 version. After this, I could execute the npm install command successfully.
Anyone having this issue and have scrolled this far, if you are installing node manually and you have nvm installed then this might be the issue, don't do it manually, and don't uninstall nvm to fix the issue, just let nvm install the version for you rather than doing it manually, if you don't have nvm installed and you are lost trying upgrading/downgrading node/npm versions, then install nvm and let it handle all these things for you.
Use nvm install x.x.x, then nvm use x.x.x, and everything worked just fine.
more about nvm
The problem may occur if you are using node version manager(nvm) try uninstalling it , i had the same issue and i uninstalled nvm and tried it .
Worked with all versions of node . (worked fine with node 10.15.3,10.16 and 12.7)
I installed Node sometime ago (approximately 1 year ago) and npm worked properly.
The node version was 10.15.3. After the install and having written a few small apps - I did not work with Node again until today. Trying to install express with npm - I got the error of: "npm ERR! Cannot read property 'resolve' of undefined" even though it had worked previously.
Noting that the Node version was old, I uninstalled and installed the latest version.
In my case, I installed into the c:\NodeJs folder (where it was installed previously).
This made no difference - I got the same error.
I then uninstalled and re-installed into the default folder of c:\Program Files\nodejs and npm works again. Hopefully this might help someone else
I encountered the same issue on Windows 10.
After uninstalling node and reinstalling a newer version, I got the error "Cannot read property 'resolve' of undefined".
I then uninstalled again, manually deleted the complete installation folder (which was not removed during uninstallation !) and reinstalled the newer node release.
After that, everything worked just fine.
The same issue occurred for me on FreeBSD after I tried to update a really outdated node installation.
After removing node and npm packages (pkg delete node8-8.16.2) I had to manually remove /usr/local/lib/node_modules directory (some npm dependencies had been left behind and that caused the problem).
Instead of version 12.18.3 install version https://nodejs.org/dist/v10.15.3/node-v10.15.3-x64.msi . It will work perfectly.
There is some issue with the new node version and npm compatibility, install version [https://nodejs.org/dist/v10.15.3/node-v10.15.3-x64.msi] It will work perfectly.

Failed at the node-sass#0.9.6 install script 'node build.js'

I'm getting this error while running npm install on project. The additional information about this issue below,
npm ERR! node-sass#0.9.6 install: `node build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass#0.9.6 install script 'node build.js'.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build.js
npm ERR! You can get their info via:
npm ERR! npm owner ls node-sass
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/capricornus/Projects/aware-app/npm-debug.log
Just install older version of Nodejs with nodebrew.
curl -L git.io/nodebrew | perl - setup
Add the following to ~/.bashrc
export PATH=$HOME/.nodebrew/current/bin:$PATH
Refresh console
source ~/.bashrc
Install older version
nodebrew install-binary v0.12.7
nodebrew use v0.12.7
Then try again!
It looks like this version is no longer compatible. I get the same errors on my system. Either you need to downgrade node to the supported version, or upgrade the dependencies that require node-sass#0.9.6.
Latest version of node-sass is 3.4.2.
In case someone runs into trouble with nodebrew, it's also possible to use nvm (node version manager) to downgrade your node version. Project on Github
On OSX El Capitan, I needed this for the installation:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
. ~/.nvm/nvm.sh
Mind the last line, as it's slightly different from the install instruction on github.
As mentioned by Yosuke Sato, v0.12.7 is compatible with node-sass#0.9.6, so you'd need
nvm install v0.12.7 or nvm use v0.12.7 (if you have it installed already)
This will use the older node version, but only in the current terminal window/tab.
nvm use v0.12.7 in the project directory followed by npm install solved the problem for me -- the error occurred as I was trying to set up broccoli-taco, a static site generator. Thanks for tip, I am glad I googled you up.

Categories

Resources