Getting errors when trying to install socket.io globally - node.js

I am new to node, npm, socket.io. Found many guides that are fairly useful, but I am encountering some errors which I don't understand the cause, hopefully you can help me out.
npm install socket.io -g
returns ...
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm ERR! error installing socket.io#0.9.4
npm ERR! error rolling back socket.io#0.9.4 Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "socket.io" "-g"
npm ERR! cwd /Users/Kinglee
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.0-beta-4
npm ERR! path /usr/local/lib/node_modules/socket.io/.npmignore
npm ERR! code EACCES
npm ERR! message EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Kinglee/npm-debug.log
however when i did npm install socket.io, there was no error, everything was fine.
Sorry forget to add this info here ...
I actually tried sudo npm install socket.io and it installed without error but when i try to cd ~/node_modules, I don't see socket.io, this cause 'socket.io not found' error when i try to do require('socket.io') as I follow this tutorial here (http://blog.koostudios.com/?p=470)
Kind of confused fellow here :/

The most important portion is:
EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
This means you do not have permission to delete this file.
I assume this means you ran the command as your standard user account, which will not have write permission into /usr/.
Prepend sudo to your command to re-run the command with administrator privileges:
sudo npm install socket.io -g
Your local configuration may not have /usr/local/lib/node_modules/ in node's default module loading locations. The module loading path is controlled via the NODE_PATH environment variable (before starting node) or the require.paths variable (once node is running). Because I prefer to keep local configuration separated from the program, I'd prefer to set the environment variable to modify paths, though the other mechanism may be useful for long-lived applications that must remain up even when the environment changes. (This is definitely an advanced use.)
To change the NODE_PATH variable for a single instance, sh and its derivatives will let you simply add NODE_PATH=/path before the command. For example, change:
node ./foo.js
to
NODE_PATH=/usr/local/lib/node_modules ./foo.js
If you have multiple directories, use the standard :-separated directories, just as you would for PATH:
NODE_PATH=/usr/local/lib/node_modules:/home/sarnold/node_modules ./foo.js
To make this persistent, use the shell's export builtin to export the value of the NODE_PATH variable to all children and place the modification in your shell's start up files, such as ~/.bashrc:
export NODE_PATH=/usr/local/lib/node_modules
This will take effect in all new shells automatically. You can source this file into currently-running shells if you don't wish to restart them:
source ~/.bashrc

Just leaving this here, as it helped me with a similar problem:
NPM no longer working
Had some good answers.
Hope it helps.

Related

Installing SKPM (Sketch Plugin Manager) via npm

I've been attempting to install a npm package, which has been throwing a bunch of errors which I'm not too familiar with. Keep in mind that these errors are after executing sudo npm install -g skpm:
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/skpm/node_modules/keytar/build'
gyp ERR! System Darwin 17.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/skpm/node_modules/keytar
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keytar#4.1.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keytar#4.1.0 install 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/USERNAME/.npm/_logs/2017-12-19T01_53_44_910Z-debug.log
Originally I'd thought that I needed to install keytar to make this work, but after installing I still had the same errors.
Avoid use sudo npm -g install
During gyp compilation you will have such problems again and again.
Fixing permissions is the solution.
Quote from npm docs:
You can fix this problem using one of three options:
Change the permission to npm's default directory.
Change npm's default directory to another directory.
Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.
Option 1: Change the permission to npm's default directory
Find the path to npm's directory: npm config get prefix For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2 or you
will mess up your permissions.
Change the owner of npm's directories to the name of the current user
(your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home
folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Option 3: Use a package manager that takes care of this for you.
If you're doing a fresh install of Node on Mac OS, you can avoid this
problem altogether by using the Homebrew package manager. Homebrew
sets things up out of the box with the correct permissions.
brew install node
usually EACCES: permission denied occurs trying to install a package globally (with -g) without providing permissions. Supposing that you are on os with sudo, try call
sudo npm install -g skpm
or, if you don't want it global
npm install skpm
I found the issue as to why skpm was not installing.
Make sure you install x-code + command line tools access
This fixed the issue and SKPM installed.

Angular2 Quickstart lite-server crashes

Good Morning people from the Internet,
Intro
While following the Angular2 Quickstart guide I have experienced many times issues where lite-server would crash just after executing npm start. Crash would look like this in your terminal:
ERR! Linux 3.19.0-51-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "lite"
npm ERR! node v5.7.0
npm ERR! npm
v3.8.2
npm ERR! code ELIFECYCLE
npm ERR! angular2-quickstart#1.0.0 lite: `lite-server`
npm ERR!
Exit status 1
npm ERR!
npm ERR! Failed at the angular2-quickstart#1.0.0 lite script 'lite-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 angular2-quickstart package,
npm ERR! not with npm itself.
npm ERR!
Tell the author that this fails on your system:
npm ERR! lite-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-quickstart
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/oscar/dev/cw/npm-debug.log
Most common reasons (and solutions)
Most of the time the reason was one of the two:
lite-server was not shutdown properly. Solution: Killing all npm / node instances and restarting the server with npm start would do the trick.
dependencies are not up to date. Solution: simply deleting the node_modules directory, executing npm install to rebuild the dependencies would do the trick.
Other issue
However when reaching the step called 6.Routing the issue was a bit different. This time instead of crashing straightaway it was failing after typescript compilation:
16.03.15 16:33:49 200 GET /index.html
events.js:154
throw er; // Unhandled 'error' event
^
Error: watch node_modules/angular2/es6/prod/examples/platform/dom/debug/ts/debug_element_view_listener ENOSPC
at exports._errnoException (util.js:856:11)
...
at FSReqWrap.oncomplete (fs.js:82:15)
I have found the cause of the crash. And I felt like sharing the path so it might help others because there are many forum / stackoverflow threads around the same sort of issue but none solved this crash.
Basically, I looked at the stack trace to find which "module" was failing. Here it is
at FSReqWrap.oncomplete (fs.js:82:15)
and the solution was to execute the following command (see this ticket):
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
but instead of just executing it, I needed to understand why setting to 524288 the config item fs.inotify.max_user_watches into /etc/sysctl.conf which is after a system file. I found the answer here where it says and I quote:
Nodejs would report an error if there's too many files for watching due to system limitation, on Linux you can change that by adding fs.inotify.max_user_watches = 524288 to the file etc/sysctl.conf and restart the process
Hope it helps.

Error: EACCES, permission denied even after using sudo?

I am trying to set up a chrome extension that will automatically save the changes I make to my website with the inspect element feature. The idea is that you'll be able to make real time changes to the website without having to go back into the ide to save the changes and re-upload and everything. The extension is called DevTools Autosave. I've been following the instructions from this site. I'm trying to install this on a mac.
I've installed node.js and the extension already. When I got to the part in the instructions where it talks about which commands to run in the terminal I've tried both with and without the "sudo" in front of the "npm install -g autosave" command but I always get this error:
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
npm ERR! autosave#1.0.3 install: `node ./scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the autosave#1.0.3 install script.
npm ERR! This is most likely a problem with the autosave package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls autosave
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "autosave"
npm ERR! cwd /Users/Brent
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
Anyone know how I can fix this? I can't find anyone that is having this problem and I've been on a few different forums now but can't find a solution. Thanks in advance.
You have two options: Either fix your npm setup, so you can use npm -g, or install autosave locally.
To install locally (i.e. in node_modules within your current directory), run npm install autosave (without -g). Then you can run ./node_modules/.bin/autosave or ./node_modules/autosave/bin/autosave to start autosave.
To fix your npm setup, so you can use -g without root permissions (recommended):
In your home dir (assuming /Users/Brent/), create a file called .npmrc with the following content:
cache = /Users/Brent/.npm/cache
globalconfig = /Users/Brent/.npm/npmrc
globalignorefile = /Users/Brent/.npm/npmignore
prefix = /Users/Brent/.npm
And add ~/.npm/lib/node_modules to your NODE_PATH, e.g. by putting the following in .bashrc (assuming that your shell is bash) to allow the modules to be found, and append ~/.npm/bintoPATHso you can run any installed binary (i.e. runautosave` from anywhere):
export NODE_PATH=$HOME/.npm/lib/node_modules
export PATH=$PATH:$HOME/.npm/bin
(changes to .bashrc only take effect when you load the shell, or use . ~/.bashrc; if you want to use the new setup without reloading the shell, just run that line (export ...) in your current shell).
As of 2020, here is the recommended solution by npm. It worked for me (OSX). (No need to change any path configuration or .bashrc)
Steps:
Install nvm by running below command.
If you are using bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
If you are using zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | zsh
Install node using nvm (No need to uninstall existing node/npm)
nvm install 12.13.1

npm install from git repo fails with ENOENT

I am trying to install one of my own packages as follows
npm install --save gfarrell/state.js
and I'm getting the following errors (full log here):
npm ERR! addLocal Could not install gfarrell/state.js
npm ERR! Error: ENOENT, stat 'gfarrell/state.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "--save" "gfarrell/state.js"
npm ERR! cwd /Users/gideon/Code/PresenceMonitor
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.10
npm ERR! path gfarrell/state.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/gideon/Code/PresenceMonitor/npm-debug.log
npm ERR! not ok code 0
Now I've tried various solutions including:
npm cache clean
sudo npm cache clean
rm -rf ~/.npm
sudo npm install --save gfarrell/state.js
npm install --save git://github.com/gfarrell/state.js.git
but nothing has changed the error output. I can't see anything wrong with the module's package.json, and I haven't added anything to my local package.json either. I actually tried installing this package on an earlier version and it worked fine, so I just don't understand what is going wrong.
Needless to say, it's all rather frustrating. Is there something else going on that I'm just not seeing?
This is most probably an authentication issue. You should add --verbose to the install command to se more output. You should see this line in your console output when running with verbose on:
npm ERR! git clone git#github.com:gfarrell/state.js Permission denied (publickey).
Check if you are authenticated to Github using the following command:
ssh -T git#github.com
When you are authenticated correctly you should see the following output:
Hi gfarrell! You've successfully authenticated, but GitHub does not provide shell access.
Github has a great guide on SSH keys as well as how to solve common errors.
Fix your Github authentication and the npm install will start working.
I had a similar issue myself. Because the last "ok" line of the verbose output started with "addRemoteGit", I traced the issue to a function named addRemoteGit in the npm source file cache.js (in v1.4.9, it has now been moved into add-remote-git.js). By adding a call to log.verbose(p), I found out npm could not write to ~/.npm/_git-remotes/.
Basically it was a permission problem: my ~/.npm directory contained files & directories owned by root. I solved the issue by simply running:
sudo find ~/.npm -exec chown $USER:$USER {} \;

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