How to update npm in Laravel Sail - npm

I am currently using Laravel 8.48.2 with the Sail package. I set Sail up and running its image through Docker Desktop while using WSL 2 with a Ubuntu distro on Windows. All seems to be working fine.
After I ran sail npm install, the packages were installed successfully, but I received the following message:
npm notice New minor version of npm available! 7.18.1 -> 7.19.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.19.0
npm notice Run npm install -g npm#7.19.0 to update!
Therefore, I tried running sail npm install -g npm#7.19.0 which gave me the following message:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/npm
npm ERR! dest /usr/lib/node_modules/.npm-qUIFSsiV
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'
npm ERR! [Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/lib/node_modules/npm',
npm ERR! dest: '/usr/lib/node_modules/.npm-qUIFSsiV'
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.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/sail/.npm/_logs/2021-06-26T15_27_02_291Z-debug.log
How can I update the NPM version on Sail?
Thank you in advance.

Current working method:
sail root-shell
npm install -g npm#latest

Looking at your log it seems the user you run as has insufficient permission on the folder /usr/lib/node_modules/. So what you might try is to log in to the container with docker-compose exec laravel.test bash and use chown -R user:group /usr/lib/node_modules/ with the current user and group (found by whoami). Or chmod the folder to have more looser permission overall on this folder.

Thanks to #online Thomas (https://stackoverflow.com/a/68173952/14508436), in order to resolve my issue, I followed these steps:
Within my Laravel project's directory, I ran this command... docker-compose exec laravel.test bash, which points you to the docker's server (or something like that), directly on your project's directory.
I ran this command... npm install -g npm#7.19.0 which updated npm to a newer version without any issues.
I tried the chown and chmod commands as suggested by #online Thomas, but in vain. I still couldn't use the sail npm install -g npm#7.19.0 command outside of the docker's server.

Related

Failed to install puppeteer using npm - connect EACCES

When I try to run a npm install, it fails at a dependency called puppeteer.
And if I run:
npm install -g puppeteer#1.5.0
(existing in package.json as "puppeteer": "1.5.0",) it fails with the following error:
npm ERR! code EACCES
npm ERR! errno EACCES
npm ERR! FetchError: request to http://registry.npmjs.org/puppeteer failed, reason: connect EACCES 104.16.27.35:80
npm ERR! at ClientRequest.req.on.err (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:182:13)
npm ERR! at Socket.socketErrorListener (_http_client.js:391:9)
npm ERR! at Socket.emit (events.js:182:13)
npm ERR! at emitErrorNT (internal/streams/destroy.js:82:8)
npm ERR! at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
npm ERR! at process._tickCallback (internal/process/next_tick.js:63:19)
but I can access that URL (http://registry.npmjs.org/puppeteer) using my browser.
The other dependencies specified in package.json work fine. Only this one generates problems.
Details:
npm - 6.2.0
node - v10.9.0
OS: Windows
Any suggestions?
npm ERR! code EACCES
npm ERR! errno EACCES
This is a permission error, on a normal day, I will say you should just use sudo npm install -g puppeteer#1.5.0, but I will suggest you reclaim ownership of the .npm directory by running this:
sudo chown -R $(whoami) ~/.npm
Then you need the write permission in node_modules directory:
sudo chown -R $(whoami) /usr/lib/node_modules
after which you can run your npm install -g puppeteer#1.5.0, This should solve your issue.
UPDATE:
I will suggest two other options for you,
from your terminal, run this:
npm config set unsafe-perm=true
OR
use yarn add for your installation.
also sometimes it just takes a while; I used npm install (I'm trying to use formkit but I'm not sure if it matters) --verbose and I'm getting a bunch of
npm http fetch GET 200 https://registry.npmjs.org/#formkit%2fvalidation
70085ms (cache stale)
so I assume its some issue that requires me to download things that take a very long time. Maybe an issue connecting to the verification server?
Edit: restarted computer, cleared cache, etc etc. Still weird and slow.
Not sure what happened but fixed it by going into my IDE (Jetbrains WebStorm) and changing my package handler in settings to a different nodejs. The one I was using was in Program Files and was having trouble accessing pieces in AppData/Roaming, There was another installation inside AppData and picking that one automatically solved my permissions issue.

Issues installing fabric-sdk-rest

I am trying to install hyperledger fabric sdk rest server. I have cloned fabric-sdk-rest repo and installed the prerequisites but when trying to run "npm link" in packages/loopback-connector-fabric I get the following error:
npm ERR! path /usr/lib/node_modules/loopback-connector-fabric
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall unlink
npm ERR! Error: EACCES: permission denied, unlink '/usr/lib/node_modules/loopback-connector-fabric'
npm ERR! { Error: EACCES: permission denied, unlink '/usr/lib/node_modules/loopback-connector-fabric'
npm ERR! stack: 'Error: EACCES: permission denied, unlink \'/usr/lib/node_modules/loopback-connector-fabric\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'unlink',
npm ERR! path: '/usr/lib/node_modules/loopback-connector-fabric' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2018-02-12T22_24_45_379Z-debug.log
This is what happens if I run it with sudo:
> pkcs11js#1.0.13 install /home/user/Documents/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/pkcs11js
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/user/Documents/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/pkcs11js/build'
gyp ERR! System Linux 4.8.0-36-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/user/Documents/fabric-sdk-rest/packages/loopback-connector-fabric/node_modules/pkcs11js
gyp ERR! node -v v9.5.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pkcs11js#1.0.13 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pkcs11js#1.0.13 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/user/.npm/_logs/2018-02-12T22_26_40_864Z-debug.log
This is done in Ubuntu 16.04. What am I doing wrong?
I was facing this errors too. After a while trying all kind of insane things to get it running I came into account that the problem was I was installing npm modules as superuser globally. This conflicts with hyperledger*.
Solutions is $: sudo npm uninstall -g *** for every module you just installed as superuser.
Then you need to install the modules not as superuser. This are some advices.
If installing Hyperledger Composer using Linux, be aware of the following advice:
Login as a normal user, rather than root.
Do not su to root.
When installing prerequisites, use curl, then unzip using sudo.
Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it's actions are required to be run as
Do not use npm with sudo or su to root to use it.
Avoid by all means installing node modules globally as root.
If you're running on Ubuntu, you can download the prerequisites using the following commands:
curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
Next run the script - as this briefly uses sudo during its execution, you will be prompted for your password.
$: ./prereqs-ubuntu.sh
This is the best way
Or you can visit this page and follow the prereqs installation guide.
Prerequisites for Ubuntu
and finally follow this link to continue the installation it works just fine.
Install development tools
This is the latest update
Hope this helps

Global install of phantomjs-prebuilt in Debian stretch

I'm trying to do a global install of phantomjs-prebuilt in a Debian Stretch VM. I realise there is a prebuilt Debian package, but...
Here's the result:
root#debian:~# npm install phantomjs-prebuilt -g
/usr/bin/phantomjs -> /usr/lib/node_modules/phantomjs-prebuilt/bin/phantomjs
> phantomjs-prebuilt#2.1.14 install /usr/lib/node_modules/phantomjs-prebuilt
> node install.js
Considering PhantomJS found at /usr/bin/phantomjs
Looks like an `npm install -g`
Could not link global install, skipping...
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
[========================================] 100%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /usr/lib/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-
x86_64.tar.bz2-extract-1498865633866/phantomjs-2.1.1-linux-x86_64 -> /usr/lib/node_modules/phantomjs-prebuilt/lib/phantom
Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1498865633866/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
errno: -13,
code: 'EACCES',
syscall: 'link',
path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1498865633866/phantomjs-2.1.1-linux-x86_64',
dest: '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1498865633866/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt#2.1.14 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt#2.1.14 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! /root/.npm/_logs/2017-06-30T23_33_57_117Z-debug.log
If I'm reading it right, it seems odd that it would download the tarball to /tmp, extract the tarball and then create a symlink to the /tmp file(s) in /usr/lib/node_modules.
Am I just doing it wrong? Other npm packages seem ok:
root#debian:~# npm install -g grunt-cli
/usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli#1.2.0
added 16 packages in 1.511s
In case it matters:
root#debian:~# node -v
v8.1.2
root#debian:~# npm -v
5.0.3

How to Fix Error "user admin is not allowed to access package"

I am updated now and running
node v5.0.0
npm v3.3.6
On a Mac (El Capitan)
When i run "npm install" on my project now. I get errors like this:
me:controls me$ sudo npm install
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/Cellar/node/0.10.36/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.0.0
npm ERR! npm v3.3.6
npm ERR! code E403
npm ERR! user admin is not allowed to access package chai : chai
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/me/Dev/controls/npm-debug.log
Im not seeing any solutions to this around the web yet? I tried both sudo and not sudo and makes no difference.
Any suggestions?
I had the same problem. Check the registry: npm config list.
Try to run:
npm set registry "https://registry.npmjs.org/"
and then npm i again.
I used sinopia as a registry. Sinopia can't work with scoped packages.

CastMyCode installation error

I try to install CastMyCode on my machine using this command: npm install -g castmycode
Unfortunately, I got this error message:
npm WARN locking Error: EACCES, open '/Users/zulhilmizainudin/.npm/_locks/castmycode-603889af8ee0127d.lock'
npm WARN locking at Error (native)
npm WARN locking /Users/zulhilmizainudin/.npm/_locks/castmycode-603889af8ee0127d.lock failed { [Error: EACCES, open '/Users/zulhilmizainudin/.npm/_locks/castmycode-603889af8ee0127d.lock']
npm WARN locking errno: -13,
npm WARN locking code: 'EACCES',
npm WARN locking path: '/Users/zulhilmizainudin/.npm/_locks/castmycode-603889af8ee0127d.lock' }
npm ERR! Darwin 14.1.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "castmycode"
npm ERR! node v0.12.0
npm ERR! npm v2.6.1
npm ERR! Attempt to unlock /usr/local/lib/node_modules/castmycode, which hasn't been locked
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/zulhilmizainudin/npm-debug.log
I'm using NPM v2.6.1.
Btw, for those of you that don't know what CastMyCode is, it's actually a simple web app that allow anybody to share their codes and let others view their codes.
It's built by one of my friend. If you're programming mentor/lecturer, CastMyCode can help your students see all your codes changes right inside their web browsers.
Solved. I run this 2 commands inside my terminal:
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/local/lib/node_modules
Then I run this command:
npm install -g castmycode
CastMyCode now successfully installed & I can use it. Thanks IBam for sharing the solution!