Can't install any Node packages globally Ubuntu Digital Ocean - node.js

Tried everything. Tried all the steps below, didn't work so I nuked my droplet and rebuilt to start over and try again. I'm Using Ubuntu. First thing once I ssh into my droplet was install node and npm via:
https://nodejs.org/en/download/package-manager/
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Then
npm -v
5.6.0
node -v
v8.11.3
Then I try to install a package globally. I tried electron and it failed so I began messing with the node modules folder as I was getting the permission error with the fix documented here:
https://askubuntu.com/questions/869168/node-modules-have-755-permissions-what-permissions-should-i-set-so-that-npm-don
No luck. So I tried the solution documented here:
NPM global install "cannot find module"
echo $NODE_PATH
/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/username/.npm-global/lib/node_modules
So that didn't work either. This is the error now when I try and install any package globally:
npm install -g electron
I get:
Error: Cannot find module '/root/.npm-global/lib/node_modules/nightmare/node_modules/electron/install.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron#1.8.7 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron#1.8.7 postinstall 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! /root/.npm/_logs/2018-08-03T03_26_03_827Z-debug.log
This error for any package I try to install. Not sure what else to try. Don't want to wipe out the droplet and start over...

I also had this issue but after adding sudo at start the issue went away.
like:
sudo npm -g install nodemon

Related

Trying Laravel jetstream but getting an error on "npm run dev"

lam getting the error below while running npm run dev
[webpack-cli] TypeError: this.program.configureOutput is not a function
at new WebpackCLI (/home/vagrant/sites/ecom/node_modules/webpack-cli/lib/webpack-cli.js:19:22)
at runCLI (/home/vagrant/sites/ecom/node_modules/webpack-cli/lib/bootstrap.js:7:21)
at Object. (/home/vagrant/sites/ecom/node_modules/webpack-cli/bin/cli.js:23:5)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at runCli (/home/vagrant/sites/ecom/node_modules/webpack/bin/webpack.js:54:2)
npm ERR! code 2
npm ERR! path /home/vagrant/sites/ecom
npm ERR! command failed
npm ERR! command sh -c mix
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2021-03-19T11_14_07_947Z-debug.log
npm ERR! code 2
npm ERR! path /home/vagrant/sites/ecom
npm ERR! command failed
npm ERR! command sh -c npm run development
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2021-03-19T11_14_07_974Z-debug.log
First, try to update your node.js file and then run "npm run dev" and if you again faced the same problem follow the following steps:
Step1: composer update
Step2: rm -rf node_modules
Step3: npm cache clear --force
Step4: npm install
Step5: npm outdated
In this step, it will update your laravel-mix version, it is in the package.json.
Step6: npm install
Step7: npm run dev
After all these steps, everything is good.
I hope it solve your problem.
I came across this problem when trying to build and run webpack (and webpack-cli locally), after check out from Github (not at all related to Laravel).
I found that I forgot to run yarn install for webpack-cli which lead to the issue that an existing version of commander#6 was used, but webpack-cli requires commander#7.
npm list commander should tell you that the webpack-cli dependency is unsatisfied. yarn install should fix it.

Install expo cli errors at the end of install

So I'm following this tutorial to try and learn React Native: https://www.youtube.com/watch?v=qSRrxpdMpVc
And in the tutorial he shows to install expo cli using the line
'npm install expo-cli --global'
But when i run that line, i get a whole bunch of warnings saying for example:
npm WARN deprecated topo#3.0.3: This module has moved and is now available at #hapi/topo. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
In the tutorial he says to ignore this but at the end of the install i get this error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! envsub#3.1.0 postinstall: `test -d .git && cp gitHookPrePush.sh .git/hooks/pre-push || true`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the envsub#3.1.0 postinstall 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\Alex\AppData\Roaming\npm-cache\_logs\2019-12-06T01_25_52_024Z-debug.log
and then when i try to run the line 'expo init first-app' to create a project i get this error:
Error: Cannot find module 'C:\Users\Alex\AppData\Roaming\npm\node_modules\expo-cli\bin\expo.js'
[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)[39m
[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)[39m
[90m at internal/main/run_main_module.js:17:11[39m {
code: [32m'MODULE_NOT_FOUND'[39m,
requireStack: []
}
I also found a similar question with an answer of try running
npm cache clean --force
npm install -g expo-cli
So i tried that but it didnt work.
Does anyone know why i would be getting these errors? I tried reinstalling node but that doesnt seem to fix it. Thanks for the help in advance, keep in mind i am completely new to react native
Assuming that you have Node 10 LTS or greater installed, you can use npm to install the Expo CLI command line utility:
npm install -g expo-cli
expo init AwesomeProject
cd AwesomeProject
npm start # you can also use: expo start

Failed at the #angular/cli#8.3.19 postinstall script

Hi I can't install the angular cli with npm install -g #angular/cli#8.3.19.
I keep getting this :
> node ./bin/postinstall/script.js
module.js:549
throw err;
^
Error: Cannot find module '/root/.nvm/versions/node/v13.0.1/lib/node_modules/#angular/cli/bin/postinstall/script.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! #angular/cli#8.3.19 postinstall: `node ./bin/postinstall/script.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the #angular/cli#8.3.19 postinstall 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! /root/.npm/_logs/2019-11-26T00_10_33_515Z-debug.log
Node version : 13.0.1
Npm version : 6.13.1
Ubuntu version : 18.04.2
I also tried without specifying a CLI version.
I tried with this command that I found online :
npm install -g #angular/cli#8.3 --unsafe-perm=true --allow-root
And it worked.
Try to run with sudo npm. On Ubuntu, you need to run with root permission. It depends on how you install node.
sudo npm install -g #angular/cli#8.3.19
On the other hand, try to install node 12 and LTS versions to have a more secure version.
Hope it helps
Try clean your npm cache before npm cache clean or npm cache verify then npm install -g #angular/cli#8.3 --unsafe-perm=true --allow-root
Steps I followed
Downgrade node version using nvm to v12.3.0
Remove ng folder from /root/.nvm/versions/node/v12.3.0/bin
Again do npm install -g #angular/cli#8.3 --unsafe-perm=true --allow-root
and it worked

Angular CLI v6.0.8 won't install

I've installed NodeJS via PPA on Ubuntu 18.04. However when running sudo npm install -g #angular/cli I get the error at the bottom of this post.
I am using node v10.6.0 and npm v6.1.0. I have tried these commands, with no luck:
A) sudo npm install -g #angular/cli#latest
B) npm install -g #angular/cli (no sudo)
C) sudo npm install -g angular-cli --unsafe-perm=true
One thing I noticed was that in case C it actually installs and works when running as sudo. But it doesn't work as a regular user ("bash: ng: command not found").
I have checked my PATH env variable and have confirmed that the result of npm bin -g (/usb/bin) is indeed in my PATH for all users.
Any help would be very much appreciated.
me#laptop:~$ sudo npm install -g #angular/cli
[sudo] password for me:
/usr/bin/ng -> /usr/lib/node_modules/#angular/cli/bin/ng
> #angular/cli#6.0.8 postinstall /usr/lib/node_modules/#angular/cli
> node ./bin/ng-update-message.js
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/#angular/cli/bin/ng-update-message.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! #angular/cli#6.0.8 postinstall: `node ./bin/ng-update-message.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the #angular/cli#6.0.8 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
FOUND IT! After much digging around I realized this was a permissions issue. A system-wide umask in the PAM module (Ubuntu) was set to create files and folders with more restrictive permissions than usual. This is what I did to get back to normal and get Angular CLI installed:
sudo vi /etc/pam.d/common-session
Then change this line: session optional pam_umask.so umask=077
To this: session optional pam_umask.so
Reboot, then: sudo npm install -g #angular/cli
Et VoilĂ !

Can't install electron because of permission error

I can't install electron via npm.
I try to execute with sudo but same error arose.
Also tried official method (https://docs.npmjs.com/getting-started/fixing-npm-permissions) but it didn't fix this problem.
os: Ubuntu 16.04
node version: 8.5.0
npm version: 5.4.2
I install electron 1.7.6 because latest version(1.7.8) has no Linux package.
npm install electron#1.7.6
electron#1.7.6 postinstall
/home/tombo/workspace/hatebu-viewer-client/node_modules/electron node
install.js
/home/tombo/workspace/hatebu-viewer-client/node_modules/electron/install.js:48
throw err
^
Error: EACCES: permission denied, link
'/tmp/electron-tmp-download-9437-1506349033474/electron-v1.7.6-linux-x64.zip'
-> '/home/tombo/.electron/electron-v1.7.6-linux-x64.zip'
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! electron#1.7.6
postinstall: node install.js npm ERR! Exit status 1 npm ERR! npm ERR!
Failed at the electron#1.7.6 postinstall script. npm ERR!
This is probably not a problem with npm. There is likely additional logging output above.
```
Could anyone solve this problem?
thanks.
I think you not have to specify the version of electron. Instead you can just install it globally first by using this command:
$ sudo npm install -g electron --unsafe-perm=true
And then init your project with command:
$ npm init
$ npm install electron --save
The global installation is necessary to run your app with comman $ electron ..

Resources