Can't install Ember Octane on Mac; problems with NPM and NVM - node.js

I'd like to install the most recent version of Ember on my Mac with MacOS Catalina. I actually thought I had done so a few weeks ago (this machine is only three months old), but ember -v says that Ember CLI is at version 3.9 which is 13 months old.
So I entered npm install -g ember-cli in the terminal, but I get an error:
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
So I did what is suggested here and tried to install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
There's some output and everything is looking finde, but when I try to verify my installation using command -v nvm, there's no output at all.
npm uninstall ember-cli gives me up to date in 0.031s.
What can I do to get Ember Octane running?
edit: I managed to install NVM using Homebrew. nvm -v says 0.35.3. But I don't find any information on how to continue from here. I still get the same error when trying to install Ember.

Your problem lies in your comment:
npm bin says /Users/<my-username>/node_modules/.bin. which ember says /usr/local/bin/ember. Now it is important to understand the PATH.
Your PATH includes multiple directories and whenever you enter a commend it will be looked up in all theese directories. Now your PATH definitly contains /usr/local/bin/ and maybe later /Users/<my-username>/node_modules/.bin. It definitly should contain borth directories. If it does not contain /Users/<my-username>/node_modules/.bin thats something you should fix immediatly.
Now however your primary problem is that you basically installed ember-cli twice in two versions with two versions of npm. At the time you've installed ember originally you didnt use nvm yet. And using npm with nvm is in some ways significantly different from using it without it.
If you're using nvm basically everything lives in your $HOME (so /Users/<username>). Also the folder where npm install -g will install binaries into, it will be /Users/<my-username>/node_modules/.bin. This is actually a good thing because this means every user can install its own things there without sudo. On the other hand if you use the global npm you will install binaries installed with npm install -g into /usr/local/bin/. This however either requires sudo or changing some permissions. We dont know what you did back then, maybe you tried it once with sudo, and since then this one version basically overwrites all other versions you may install later with nvm because /usr/local/bin/ comes in your PATH before /Users/<my-username>/node_modules/.bin.
Now what you should do is get rid of /usr/local/bin/ember first. For this you do ls -lisa /usr/local/bin/ember because this is probably a symbolic link to somewhere else. Then you check where this link leads to and remove ember-cli from there. It is probably safe to just rm -rf the packages installed there. Next you delete the symbolic link /usr/local/bin/ember itself. Then run which ember again. Not this should either either fail or point to a different path. If it points to a different path you can verify that it is the version you want (in /Users/<my-username>/node_modules/.bin). If it fails you should verify that /Users/<my-username>/node_modules/.bin is actually in your PATH and that ember exists in /Users/<my-username>/node_modules/.bin.
Besides that I want to mention that ember-cli also has some interesting detail: if you run ember-cli inside an ember project it will search for the ember-cli installed inside this project and start it. So the global installed ember-cli version actually doesnt matter that much. It is basically only relevant for ember new. However for ember new you maybe want to consider to use npx because then you will always run the current version. So you could do npx ember-cli new my-app.

Related

npm WARN: npm does not support Node.js v12.4.0

I've been getting the following warnings lately whenever I run any npm script:
npm WARN npm npm does not support Node.js v12.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/
It says that I should upgrade to a newer version, but v12.4 is the newest version. Even though the scripts run fine, I think there's no guarantee and something might break at any moment.
I've also tried updating npm in case there's a newer version using npm install npm -g but got the error:
npm ERR! path /usr/local/Cellar/node/12.4.0/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'] {
npm ERR! stack: 'Error: EACCES: permission denied, access ' +
npm ERR! "'/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
Then I've seen that Homebrew version of npm can't be updated using npm itself, so I tried updating through Homebrew using brew upgrade npm but got this error:
Error: npm 12.4.0 already installed
For some reason Brew mixes up nodes and npms versions.
What am I doing wrong and how can I get rid of this warning?
What worked for me:
if you try running this command "npm cache clean -f" and it doesn't work,
on your windows machine(mine is windows 10)
access the "npm" and "npm-cache" folders in this location "~\AppData\Roaming\"
delete these two folders "npm" and "npm-cache".
go to your windows search bar and search for Node, right click to open file location, run the uninstaller to uninstall NodeJs.
then visit nodejs.org and download and install node again, if you've already downloaded it, visit the folder where you downloaded it to reinstall it.
after installation, check your version of npm by typing "npm -v" on your command terminal to see the new updated version of npm installed on your machine.
now you're all set, Happy coding.
Seems like you messed up with permissions in /usr/local.
Here is how to fix that:
Fix /usr/local permissions:
sudo chown -R `id -un`:`id -gn` /usr/local
Clean npm cache and uninstall it:
npm cache clean -f
npm -g uninstall npm
Reinstall node (with npm)
brew reinstall node
Upgrade npm:
npm -g i npm
That should bring npm#6.9.2.
You should avoid using sudo while installing software with brew or npm, that could cause issues like this.
If you have nvm you may have an issue in which your node version installed at a certain version didn't match.
For example, I accidentally used: npm i -g node --force resulting in my nvm v12.21.0 to point to v16.5.0 (the latest version of node at that time directly downloadable).
To solve: I ran:
Just for good measure brew uninstall nvm
brew install nvm.
nvm uninstall 12.21
nvm install 12.21
Just for good measure I ran npm i -g npm resulting in the latest version of npm installed on that virtual node.
After installing within some repo (using npm i) you may also want to check your: ~/.npmrc.
email=myemail#company.com
registry=https://artifactory.company.com/npm/npm/
always-auth=true
user-agent=npm/6.14.11 node/v12.21.0 darwin x64
_authToken=siofjwoirgiowrgnioaenrvoianeoiio32noi23nio23nio23nio
It should look something like this: (or you might not have any of that.
Had the same issue with Debian 10 (buster) when I tried installing the npm and node.js. They were incompatible and wouldn't update. This was what I found works for me.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
The nodejs package was installed at a different path and I manually deleted the old package (in /usr/bin/) and added a symlink to point to the new one (in /usr/local/bin).
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
This is the initial printouts from running the commands. The npm version updates from 5.8.0 to 8.1.2. But the nodejs version stayed at 10.24.0 even after reboot with hash -r.
None of the answers here worked. I had to delete the npm and npm-cache folders, then reinstall npm. Details here: npm does not support Node.js v12.18.3
After step 4 posted by Styx, and if node claims installation fo a newer version but npm -v keeps showing outdated version
Code for Mac and node installed with brew:
cd /usr/local/bin/
mv npm npm-backup
mv npx npx-backup
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
npm -version
6.14.5
I hit this issue and the steps above didn't work for me. I think it can happen if you try to upgrade Node or NPM without updating the other also. At least I think that's what happened to me.
I was trying to create a new Angular project and I had a very old version on my machine. I got an error to upgrade Node, so I bumped it to the latest version. After that I got the error running any npm command.
I resolved it simply by going to:
https://nodejs.org/en/download/
Getting the latest version and installing that in a pkg file (mac). After install was complete I was able to run everything. I'm guessing it worked because the versions of each mismatched, so one wouldn't run without the other being downgraded.
I also tried the brew option but I was getting other issues. My corporate machine sometimes blocks installations in that route, so it might work for others.
For Windows, this was driving me crazy, and all of the above solutions were not working, I would still get the old version of node showing for node -v.
For me simply killing the terminal window and starting it again resolved the issue. No amount of cache clearing worked until this. I know it sounds dumb, but that's what resolved this for me in the end. Hope this helps someone else not lose hours farting around with this.
I've have this issue in npm -v package,so you have to easy step in follow of solve this problem.
npm use stable
nvm use stable
nvm cache clear
nvm install stable --default
you can closed the terminal then check the `npm --version
Looks like a permission issue. Try with sudo

npm install not working. Says that I need to check permissions?

I'm trying to install eslint on my machine right now but it is saying that I need to check permissions because its missing write access to /user/local/lib/node_modules. Does anyone know how to fix this? Thanks!
npm install -g eslint
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mkaplan/.npm/_logs/2019-03-03T18_05_46_487Z-debug.log
Try sudo npm install -g eslint
For Linux use sudo npm install and
For Window run powerShell as administrator and got to directory of project and run npm install
In my case I had this same problem to install angular, so just change the command to :
$ sudo npm install -g #angular/cli
This kind of stuff happens when you run npm commands with sudo to begin with. So don't do it?
If this happens, it means that someone has been messing around npm as root. Then root took and created files in global npm cache, denying access to anything different than root.
This is why it fires EACCES when running npm install or npm install -g
You are not supposed to do anything related to node_modules nor runnpm [anything] with sudo. Do you understand that you are giving the package in question permission to do whatever it wants? Even if you check the package and ensure its security yourself, what about dependencies it downloads? will you check them as well?
npm registry gets 30b weekly downloads, their malware control is nowhere near enough
You are giving away access to whole sys folder tree to the files of the package in question. Even npm itself gives you feedback that it is not recommended. You do not know what package does in the background. What if you install a package i developed, but i am a villian who likes to make people's life harder... This is a security issue.
The above story apart. If you do it with sudo, this will force you to run certain npm commands as sudo from that point on, messing it up even more.
The maximum you do as root in this case, is give access for node_modules to whoami
The best solution is to either set it up properly so you dont have to use sudo or run app in container, so anything you do is executed inside container, not affecting your local machine at least. Even there it is not recommended to mess around as root, permissions get so messy... it's a hell to debug.
I'm fairly new to Node but as a longtime Linux user I'not sure installing node packages as root (via sudo) is a good idea.
I imagine eslint is fine but if you're having this issue installing one package then I'm guessing you're having the same problem with every package you're installing globally ('-g'). That means that every time you install a package from npm globally you're downloading who-knows-what install script and running it with root privileges on your computer.
Anyway, as I said I'm no Node expert but I had this same problem and my issue was that I'd installed the "nodejs" package using apt. If this is what you did then I suggest:
Remove nodejs with sudo apt remove nodejs. (Depending on what Linux distro you're using this may be different. I'm running Ubuntu.)
Install nvm or some other node version manager as recommended by the NPM docs.
When I did this, I was able to install NPM packages globally without sudo.
(Yes, I'm telling you not to install things by running npm as root and then saying you should install things by running apt as root. But you definitely need to run apt as root and I know appropriate precautions are taken by the apt devs and Ubuntu package repo managers. I'm not 100% sure it's wrong to run npm as root but I'm not sure it's right either, and I was able to avoid running it as root using the above steps.)
This can solve the problem:
sudo npm install -g npm
First try sudo npm install -g gatsby-cli
then npm start
I ran into an issue trying to install truffle and got the following errors:
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
I was able to solve this issue with the recommendation to add 'sudo'.
solution:
sudo npm i -g truffle
Use the command:
sudo npm install -g eslint
With the sudo command you will have the permission to install.
This might happen when you just "sudo" everything in order to make it work or you install a dependency forcefully , you should not mess with the root folder of node modules.
For now you can try installing using
sudo npm install -g eslint
Use this npm install node-sass --save

How can I install `bcrypt-as-promised` from an old code base onto my ubuntu box?

I'm working with an old code base from an old project that uses bcrypt-as-promised (before bcrypt allowed the use of promises). When I try and npm install the package.json, I receive this error for that package:
npm WARN deprecated bcrypt-as-promised#1.1.0: the bcrypt module supports promises now, this module is no longer necessary
npm WARN deprecated bcrypt#0.8.7: bcrypt < v2.0.0 is susceptible to bcrypt wrap-around bug. Upgrade to bcrypt >= v2.0.0 for improved support for newer bcrypt hashes
And then proceeds to fail (I can paste more of the error message if needed).
I'm a little confused as to how I might be able to get this now deprecated package to install. I thought about modifying the codebase to only use bcrypt (with the now native promises supported), but I'm afraid of diving into a bee's nest and breaking the application. I was wondering first if there might be a way to install this package for the old code base to get it working.
Any thoughts? Thanks for your time and any insight you may have.
My package.json: https://github.com/twknab/mean_hike/blob/master/package.json
// Edit:
Here's the full terminal message I receive when I try and sudo npm install:
> bcrypt#0.8.7 install /var/www/mean_hike/node_modules/bcrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir
'/var/www/mean_hike/node_modules/bcrypt/build'
gyp ERR! System Linux 4.4.0-1072-aws
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 /var/www/mean_hike/node_modules/bcrypt
gyp ERR! node -v v11.2.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt#0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt#0.8.7 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! /home/ubuntu/.npm/_logs/2018-11-27T10_46_27_925Z-debug.log
Older versions of bcrypt can be quite tricky to install, and it looks like you're hitting a classic permissions issue with npm. You can try some of the tips listed in the official documentation here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
… but in the meantime, here are a few things to try:
Attempt a global install of node-gyp first, either with or without
sudo: npm install node-gyp -g
If that works, then try installing
bcrypt (again, globally).
If you're still seeing permissions issues,
you may need to sort out ownership of your node_modules directory:
sudo chown -r XXX /usr/lib/node_modules/ (assuming that's where
the global modules directory is on your machine of course).
I found a solution to my issue was to use yarn to import all of my dependencies rather than npm, while also swapping bcrypt-as-promised for bcrypt (which now includes promises with no syntax changes necessary).
I ditched bcrypt-as-promised and replaced it with bcrypt in my package.json file.
I then changed any instance of require('bcrypt-as-promised') to require('bcrypt') (the syntax for using bcrypt remains the same, just the dependency importation lines need to change).
Without using yarn, even after changing my folder permissions, I was still hitting permissions "EACCES: permission denied" errors, with only bcrypt failing. My versions of npm and node seemed fine. Made sure my Ubuntu box was all updated.
That's when I gained the suggestion from a wise friend to try using yarn to grab the dependencies instead. I ran yarn import which reads the package.json file and creates a yarn.lock file. I then installed yarn on my ubuntu machine (sudo npm install yarn -g), and ran yarn install, and bcrypt successfully installed!
Update Jan 2019 - Improved Solution
It looks like if npm dependencies were originally installed using sudo, permission issues can be experienced when trying to install bcrypt. My improved solution was to:
Nuke the ./node_modules folder via sudo rm -r ./node_modules
Install npm packages fresh (not using sudo).
After this, I was able to npm i --save bcrypt with the package installing
successfully.
Here's a link from GitHub that helped me find the solution and an excerpt:
#Mayocampo permission denied, mkdir
'/home/someroute/node_modules/bcrypt/build'
It seems you run rpm as root, therrfore your account cannot mkdir
under /home/someroute/node_modules/ Check dir with ls -l
/home/someroute/node_modules/ Im sure owner of upper dir is root. or
your account cannot have permission.
I guess there are two options are available.
sudo rm -r ./node_modules And install package via npm
again, but without using sudo.
Change mod ./node_module to access and excutable. I decided first, and its fixed
Source: juicycool92 # GitHub

npm install no longer possible after deleting module directory

So I wanted to help out, and forked a Node-RED module to make some small contribution, but then got lost messing around with how to get Node-RED to run my fork (for testing) rather than the packaged version. Then I learned about npm's ability to install from a Github URL, which is nice, but it wouldn't work because I had already installed the module. Then I found I couldn't uninstall it either
npm uninstall original-module
npm ERR! path /home/nodered/.node-red/node_modules/original-module/package.json
npm ERR! code ELOOP
npm ERR! errno -40
npm ERR! syscall open
npm ERR! ELOOP: too many symbolic links encountered, open '/home/nodered/.node-red/node_modules/original-module/package.json'
so in frustration I deleted the module's directory, only to find myself unable to move forwards, or backwards. npm install https://github.com/me/forkedmodule fails with
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github.com/me/forkedmodule.git /root/.npm/_cacache/tmp/git-clone-d31dc53b
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-d31dc53b': Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_07_18_257Z-debug.log
and trying to install the original with npm install original-module fails with
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/original-module" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_09_56_127Z-debug.log
As you've probably guessed, I'm pretty new to Node.js, Node-RED and npm, but I haven't been able to help myself, so have to ask for help! It seems nonsensical to me that npm appears to be looking for a local copy of the package.json file belonging to the package I'm trying to install?
Edit: I should add that the above commands were all run as root.
Ok, found a solution, not sure if it's the best one though!
In the "project" directory (/home/nodered/.nodered in my case) there's a package-lock.json file which lists the packages used by the project. In there I found an entry for the original-module which I removed, after which I was able to install the package "normally" with npm install original-module.
Then to solve the permission issue when installing from a GitHub URL, I found I needed to impersonate the "nodered" user with su - nodered (it's a password-less user in my case). As "nodered" npm install https://github.com/me/forkedmodule succeeded without any error. A little curious since I was trying to do this as root before, and got a permission error, but there you go. I also took the opportunity to chown -R the project's node_modules directory to nodered:nodered as I could see that was a bit of mess.
In future, I will try to remember to su - to my nodered user first, and navigating to the project root (again, /home/nodered/.node-red in my case) before running npm install anything. Hopefully that will avoid any further issues. Oh and a note to anyone else who just wants to contrib some quick changes to a module hosted on GitHub: to "pull" in changes you simply run npm install https://github.com/me/forkedmodule again - npm doesn't appear to provide any dedicated "update" method.
I had the same issue, in my case the solution was to delete the package-lock.json, delete node_modules, then reinstall npm modules.

Polymer CLI - npm error code 1

I get this error when trying to install polymer CLI. I keep on getting this whenever i try to install it.
sudo npm install --unsafe-perm -g polymer-cli
Password:
npm WARN deprecated bower#1.8.0: ..psst! While Bower is maintained, we
recommend Yarn and Webpack for *new* front-end projects! Yarn's
advantage is security and reliability, and Webpack's is support for
both CommonJS and AMD projects. Currently there's no migration path but
we hope you'll help us figure out one.
npm WARN deprecated #types/assert#0.0.29: See
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/12826
npm ERR! code 1
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master
git://github.com/polymerelements/test-fixture.git
/Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b
npm ERR! /Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b/.git:
Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/litsonthomas/.npm/_logs/2017-06-22T17_39_34_600Z-
debug.log
I am new to polymer and I don't know where am getting wrong!
This seems to be a pertinent issue in this package (issues in the repository: #784 #800). You have to go to the npm site on Fixing npm Permissions and follow the steps there.
You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.
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.
Whether you should follow one of the three options depends on each particular case. What I would recommend first is to try changing the npm default directory to some place with user read/write permissions. Then, you should start doing npm i -g without sudo.

Resources