sudo npm install gives me a access denied - node.js

I am using ionic and I have fetched my project through git from machine1 to machine2.
My ionic infos gives me this :
[ERROR] Error with ./node_modules/#ionic/app-scripts/package.json
file: FILE_NOT_FOUND
cli packages: (/usr/local/lib/node_modules)
#ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
local packages:
#ionic/app-scripts : not installed
Ionic Framework : ionic-angular 3.7.1
System:
Node : v8.9.1
npm : 5.5.1
OS : macOS High Sierra
Misc:
backend : pro
When I run sudo npm install I get the following :
npm WARN checkPermissions Missing write access to
/Users/gerald/Documents/ionic/yesterdayweather/node_modules npm WARN
checkPermissions Missing write access to
/Users/gerald/Documents/ionic/yesterdayweather/node_modules/#ionic
And then
gyp ERR! configure error gyp ERR! stack Error: EACCES: permission
denied, mkdir
'/Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-sass/build'
gyp ERR! System Darwin 17.2.0 gyp ERR! command
"/usr/local/Cellar/node/8.9.1/bin/node"
"/Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-gyp/bin/nod
e-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags="
"--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd
/Users/gerald/Documents/ionic/yesterdayweather/node_modules/node-sass
gyp ERR! node -v v8.9.1 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok
Build failed with error code: 1 npm ERR! code ELIFECYCLE npm ERR!
errno 1 npm ERR! node-sass#4.5.3 postinstall: node scripts/build.js
npm ERR! Exit status 1
I have tried the following solution 1 and 3.
Basically I think I had node installed in a pkg way, so I removed it and intalled it with brew, so actually I should not have this issue.
But I tried anyway option 1 and it still does not work.
Any idea ?
Thanks !

It looks like a script is trying to write files, which npm by default denies when running as root. You can put --unsafe-perm behind the command to disable this safeguard.
You also should not run npm install with sudo because it is not necessary. Only when using the -g flag for installing modules globally should you use sudo.
2019 EDIT: It goes without saying that disabling safe guards like this can be very dangerous because you're giving a script a free pass to do whatever it wants. It's best to never use sudo and npm together, even when installing modules globally. If you're running into access issues with npm look into using a version manager or changing npm's default directory.

You shouldn't use sudo npm install. Clean up your environment (see more in my answer here) and then run just npm install.

Related

npm building issues for SyntaxHighlighter

I'm a beginner with npm and is trying to build SyntaxHighlighter version 4 by cloning it using git first, but failed. Here are the errors I got:
1 error generated.
make: *** [Release/obj.target/binding/src/create_string.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/name/syntaxhighlighter/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:311:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/usr/local/bin/node" "/Users/name/syntaxhighlighter/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/name/syntaxhighlighter/node_modules/node-sass
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN notsup Unsupported engine for karma#0.13.22: wanted: {"node":"0.10 || 0.12 || 4 || 5"} (current: {"node":"12.16.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: karma#0.13.22
npm WARN syntaxhighlighter#4.0.1 No description
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass#3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass#3.13.1 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! /Users/name/.npm/_logs/2020-04-05T02_52_17_048Z-debug.log
The problem you are running into is that SyntaxHighlighter version 4 is too old and its dependencies are not supported by the version of Node you are running.
The package that the error is coming from is Karma. The version of Karma that is trying to install is v0.13.22. That version of Karma only supported a maximum Node version of 5, and you appear to be running version 12.
You could potentially solve this issue by downgrading your Node version, or using a tool like Node Version Manager (NVM) to temporarily downgrade your Node version.
NVM
Try to install node_modules only.
cd /syntaxhighlighter/node_modules$ and then try installing using npm install.
There are some errors in gulp.js file that are causing problems in the installation process. I have tried older versions but none of them is available. Hope this will work out.
robdonn's NVM solution works, however, I had a very unusual instance when running multiple versions of Node, managed through NVM, was breaking my ApiConnect/Loopback client (only on a Mac). I never figured out why but realize that running a single version of Node fixed the problem.
Also wanting to use syntaxhighlighter, I did manage to generate the syntaxhighlighter.js file using a Docker container. In the cloned directory I added the Dockerfile.
FROM node:5
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
Thereafter I was able to:
Build a local docker container
docker build -t syntaxhighlighter .
Run the container mapping my local dist directory to the container's dist directory
docker run -i --volume ~/github/syntaxhighlighter/dist:/usr/src/app/dist syntaxhighlighter
Got the container id for the local running container
docker ps
Used the container id to go into the container (could have also just put CMD ['/bin/sh'] in my Dockerfile)
docker exec -it <the-container-id> /bin/sh
Ran the gulp build from the Node v5 container. Since I am mapping my local dist directory to the container's dist directory, I get the output locally.
./node_modules/gulp/bin/gulp.js build --brushes=all --compat

node-gyp rebuild fails on Mac OS High Sierra while npm install

I am getting following error in the terminal, while it tries to install one of package "node-expat". I have tried switching to different node version using nvm but still it is failing with same error.
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/node-expat
npm ERR! node v6.5.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! node-expat#2.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat#2.0.0 install script 'node-gyp rebuild'.
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 node-expat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs node-expat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls node-expat
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! c:\<redacted>\npm-debug.log
I went ahead installing x-code as suggested on git hub page, on my machine and then it is giving following error,. Not sure how to debug further.
xcode-select: error: tool 'xcodebuild' requires Xcode,
but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
I just got it fixed on my machine and my fellow colleagues machine.
Followed the following steps to fix it on MacOS highSierra 10.13:
Downloaded command line tools (MacOS 10.13) for xcode and installed it.
Download it from "https://developer.apple.com/download/more/"
Installed xcode 10.0 from the app store. Opened xcode and went through the regular configuration xcode does in the initial start up.
After this it started giving "xcode-select" path issue as stated in the description above. On running command "xcode-select --print-path" it was showing path as '/ Library/Developer/CommandLineTools', so i went ahead and tried "xcode-select --reset" after which the path changed to "/Applications/Xcode.app/Contents/Developer".
Immediately after it the build started working without any issues.
Solution above mentioned by Luke worked partially for me (MacOS) but created another issue :
gyp ERR! stack Error:makefailed with exit code: 2 which was solved by removing locked json file. Issue was created due to permission in MAC OS. So if you have xcode re-installed already, open terminal (command line) and type:
xcode-select --reset
then go to your project folder and remove:
package-lock.json
Now in terminal reinstall project :
npm install
I hope this helps someone!

Error while installing nodeshark

Hello I am install nodeshark from npmjs, but I have and error:
ubuntu#ubuntu:~/Documents$ sudo npm install nodeshark -g
(node:8720) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
> nodeshark#0.0.5 install /usr/local/lib/node_modules/nodeshark
> node mnm.js build
ERROR: Could not find "/usr/lib/i386-linux-gnu/glib-2.0/include" check GLIB_CONFIG_INCLUDE_DIR environment variable.
npm ERR! Linux 4.4.0-22-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "nodeshark" "-g"
npm ERR! node v6.2.0
npm ERR! npm v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! nodeshark#0.0.5 install: `node mnm.js build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodeshark#0.0.5 install script 'node mnm.js build'.
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 nodeshark package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node mnm.js build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs nodeshark
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls nodeshark
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! ubuntu#ubuntu:~/Documents/npm-debug.log
I have tried to install build-deb wireshark, but still don't work.
It seems that I need i386 for it to work, but I have this :
Linux ubuntu 4.4.0-22-generic #40-Ubuntu SMP Thu May 12 22:03:46 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Can someone explain how I can solve this ?
It looks like it cant locate or dosent have the glib on line
ERROR: Could not find "/usr/lib/i386- linux-gnu/glib-2.0/include
You should make sure that file is available at the path specified or add the path to this file in the environment variables
if you haven't installed it previously
sudo apt-get install libperl-dev
sudo apt-get install libgtk2.0-dev
Another possibility is that it is incompatible with 64 bit systems, If this is true and also possible you can run it in a 32 bit vm (probably the best solution if you don't intend to reinstall a 32 bit distribution)
It is looking for a 32 bit library but you are running a 64 bit version of linux
you could try changing the library path to your version of this library
It appears that mnm is required to run this software if you haven't already installed it run
npm install mnm

Error when installing log.io using npm

I am trying to install log.io following the instruction from https://github.com/NarrativeScience/Log.io. It suggests using npm install command.
npm install -g log.io
The error I am getting is like below. And I tried on both Mac OS and Ubuntu, both no luck. Can anyone help me?
> contextify#0.1.13 install /usr/local/lib/node_modules/log.io/node_modules/jquery/node_modules/contextify
> node-gyp rebuild
npm http GET https://registry.npmjs.org/cssstyle
npm http GET https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/cssstyle
gyp: Call to 'node -e "require('nan')"' returned exit status 1. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.13.0-32-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/log.io/node_modules/jquery/node_modules/contextify
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
npm ERR! Error: ENOENT, chown '/usr/local/lib/node_modules/log.io/node_modules/jquery/node_modules/jsdom/node_modules/request/README.md'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
...
Finally I found the problems.
Ubuntu
On Ubuntu 14.04, the default repository of apt-get for node is not nodejs itself, but ax25-node. This will generate a default command node in /usr/sbin/ and does nothing if you call node (which is called by npm during the installation). I removed this package and created a symlink between node and nodejs, finally solved the problem.
sudo apt-get autoremove node
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo npm install -g log.io
Mac OS
The error log is quite different from what I got from Ubuntu. After some googling about node-gyp installation failure, I found this issue, which led me to install the Xcode dev tools. Not sure why this happens but it seems there are some conflicts between homebrew and Xcode. Anyway, it finally works :-)
This looks like a race condition in an older version of npm. There have been a lot of improvements to npm -- especially around conflicts and race conditions during install -- since 1.4. Can you try updating your npm installation?
To update npm on Windows, follow the instructions here: https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows
If you still see the problem after updating npm, could you please upload your npm-debug.log as a gist http://gist.github.com? If possible, run npm with at least one -d flag to increase the logging level.
Thanks!
i create this install package...
http://tinyurl.com/kfnfng6
1 - download it
2 - untar it (tar -xvf install_log.io.tar)
3 - cd install_log.io
4 - sh install.sh
5 - enjoy!
This form is simple and quiet.. i hope help other users... What i do? simple.. download packages and dependencies , and put all in one package and create a script...
;)

nodejs npm package | npm link issue

I am trying to make a npm package (plugin) to install the little JS framework through node, have come up with the required package.json as well.
After running the npm link command on Mac terminal, got to see the following errors.
npm ERR! Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR! { [Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Repos/GIT/JavaScript-Boilerplate' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "link"
npm ERR! cwd /Repos/GIT/JavaScript-Boilerplate
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Repos/GIT/JavaScript-Boilerplate
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Repos/GIT/JavaScript-Boilerplate/npm-debug.log
npm ERR! not ok code 0
P.S. I am pretty new to nodejs but have strong experience in JavaScript, let me know if you need more detail around.
EDIT - Got to resolved the issues given above but now getting more issues as below:
6495 verbose false,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/node_modules unbuild contextify#0.1.5
6496 info postuninstall contextify#0.1.5
6497 verbose about to build /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery
6498 info /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery unbuild
6499 verbose from cache /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/package.json
6500 info preuninstall jquery#1.8.3
6501 info uninstall jquery#1.8.3
6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild jquery#1.8.3
6503 info postuninstall jquery#1.8.3
6504 error contextify#0.1.5 install: `node-gyp rebuild`
6504 error `sh "-c" "node-gyp rebuild"` failed with 1
6505 error Failed at the contextify#0.1.5 install script.
6505 error This is most likely a problem with the contextify package,
6505 error not with npm itself.
6505 error Tell the author that this fails on your system:
6505 error node-gyp rebuild
6505 error You can get their info via:
6505 error npm owner ls contextify
6505 error There is likely additional logging output above.
6506 error System Darwin 12.3.0
6507 error command "node" "/usr/local/bin/npm" "link"
6508 error cwd /Repos/GIT/JavaScript-Boilerplate
6509 error node -v v0.10.4
6510 error npm -v 1.2.18
6511 error code ELIFECYCLE
6512 verbose exit [ 1, true ]
enter code here
enter code here
Looks like I am close to it :)
Permissions you used when installing Node will be required when doing things like writing in your npm directory (npm link, npm install -g, etc.).
You probably ran node installation with root permissions, that's why the global package installation is asking you to be root.
Solution 1: NVM
Don't hack with permissions, install node the right way.
On a development machine, you should not install and run node with root permissions, otherwise things like npm link, npm install -g will need the same permissions.
NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.
Uninstall Node (root permission will probably be required).
To remove all previously installed npm global modules, see those answers.
Then install NVM following instructions on this page.
Install Node via NVM: nvm install stable
Now npm link, npm install -g will no longer require you to be root.
Solution 2: Install packages globally for a given user
Don't hack with permissions, install npm packages globally the right way.
If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup npm and node to know how to find globally installed packages.
Check out this great article for step by step instructions on installing npm modules globally without sudo.
See also: npm's documentation on Fixing npm permissions.
The easiest way to solve this would be to run the same command again using sudo:
sudo npm link
Please don't change the owner of the /usr/local directory, as this might a) have further implications on installed application and b) might compromise the security on your system. Using sudo is the right way to solve this.
This can be fixed in linux or in my case WSL by setting the global package directory to be in user space rather than root.
First create a dir for global packages
mkdir ~/.npm-packages
Then tell npm where to store globally installed packages
npm config set prefix ~/.npm-packages
Finally ensure npm will find installed binaries and man pages by adding the following to your .bashrc/.zshrc:
NPM_PACKAGES=~/.npm-packages
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

Resources