Unable to update npm from 6.14.8 to 7.3; deleting npm.cmd, npx.cmd, and npm leads to more errors - node.js

I've been attempting to update my npm globally using the npm install -g npm command in Git Bash to keep it current with Angular 11 and Node.js version 15.5.0. I receive the following error:
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
I deleted the file from nodejs and attempted to install again, but received another error about the npx.cmd. I deleted that file, attempt installation, and received an error about the npm file.
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npx.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! Refusing to delete C:\Program Files\nodejs\npm: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
After deleting them and attempting to install npm again, Git Bash no longer finds npm. The installation never starts.
bash: /c/Program Files/nodejs/npm: No such file or directory
I tried to delete the npm file from my roaming folder in AppData, but received the following error:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
I've also tried the following at different times:
Delete node_modules and reinstall npm
Used npm 7.3.0's Git repository to create a new npm file (?) (I will need to find the suggestion online again to clarify/provide more specifics)
Clean caches
Uninstall and reinstall Angular 11 CLI and Node.js (tried for both LTS and Current version)
Nothing has worked so far. The second method I tried in the above list was able to update it to 6.14.10, but this attempt returned errors that seemed to affect Angular. I reverted everything to the original state to be safe. Please let me know if I can clarify anything else regarding my issue.

I connected with another developer about the errors I've been receiving. The following approach was suggested, and it works for fixing the problem for LTS: How to completely remove node.js from Windows
The LTS version allowed me to update to npm's 6.14.11, but when I tried this approach to install the Current version, it stayed 6.14.11. Hopefully, this approach helps others who are experiencing similar errors.

Related

I can't use "create-react-app" ("This is related to npm not being able to find a file.")

I tried every single thing I've found, but I just can't run create-react-app. I tried to uninstall node and install again, use yarn, clean cache, create with "npm init ..." but nothing works.
Microsoft Windows [versão 10.0.19043.1889]
(c) Microsoft Corporation. Todos os direitos reservados.
C:\Program Files (x86)\Windows Resource Kits\Tools>cd C:\Users\user\meu_app
C:\Users\user\meu_app>node -v
v16.17.0
C:\Users\user\meu_app>npm -v
8.18.0
C:\Users\user\meu_app>npx create-react-app myapp
npm ERR! code ENOENT
npm ERR! syscall spawn C:\Users\user
npm ERR! path C:\Users\user\meu_app
npm ERR! errno -4058
npm ERR! enoent spawn C:\Users\user ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Local\npm-cache\_logs\2022-09-02T19_06_17_314Z-debug-0.log
I have never seen this issue before. npx is distributed with npm 5.2+, so that shouldn't be the issue. It seems your issue is similar to this one Can't install any NPM package, error 4058
Try these steps:
Delete package-lock.json and run NPM again (probably can skip this one if it does not pertain to your issue)
Ensure no other processes of node.js are running (check task manager)
If you are using visual studio code, close it and try running npm install again.
If all else fails, restart your computer.
See thread here: https://github.com/npm/npm/issues/17444
Let me know if that helps; otherwise, I will keep looking.

how to fix npm error in Mac in visual studio code

How do I fix this error?
USER#Bahus-MacBook-Air metaplex-master % npm --version
8\.5.2
USER#Bahus-MacBook-Air metaplex-master % npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/USER/Desktop/solana devnet/metaplex-master/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/USER/Desktop/solana devnet/metaplex-master/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USER/.npm/\_logs/2022-03-24T13_07_17_630Z-debug-0.log
How do I fix this npm installation error in visual studio code in Mac?
The error message says that the path where you are executing npm i command doesn't have package.json file.
Make sure to change the path to the place where the package.json file is located.
I'm assuming you are trying this project https://github.com/metaplex-foundation/metaplex
And you are probably running npm install in the main directory. But if you read the instalation documentation which you definitely should, then you would see cd metaplex/js which means you need to run npm install within the ./js folder since that's where the package.json is, which is required by npm install command.

How can I install nodejs manually in Linux from terminal

I have downloaded Nodejs in my Linux VM from nodejs.org, I want to install it from terminal. VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. As I am installing nodejs offline, I should not depend on that whether or not npm installed.
I have tried [location]~ npm install node-v15.6.0-linux-x64.tar.gz
Getting below error
[host#machinename ~]$ sudo npm install node-v15.6.0-linux-x64.tar.gz
npm WARN excluding symbolic link bin/npm -> ../lib/node_modules/npm/bin/npm-cli. js
npm WARN excluding symbolic link bin/npx -> ../lib/node_modules/npm/bin/npx-cli. js
npm ERR! addLocal Could not install /home/usermachinename/node-v15.6.0-linux-x64.tar.g z
npm ERR! Linux 3.10.0-1062.9.1.el7.x86_64
npm ERR! argv "/usr/local/lib/nodejs/node-v0.12.18-linux-x64/bin/node" "/usr/loc al/lib/nodejs/node-v0.12.18-linux-x64/bin/npm" "install" "node-v15.6.0-linux-x64 .tar.gz"
npm ERR! node v0.12.18
npm ERR! npm v2.15.11
npm ERR! path /tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, open '/tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package .json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/usermachinename/npm-debug.log
How can I fix this?
You can't install the file using npm install, but since you already have the compressed file for node, my answer will hopefully help you achieve your goal.
First of all you will have to extract the tar.gz file you have node-v15.6.0-linux-x64.tar.gz, to do so just navigate to the folder where the file placed in then do the below command.
tar xf node-v15.6.0-linux-x64.tar.gz
Since you're using Linux the below command will add the new extracted node to your path.
nano ~/.profile
Add the following lines to the end:
# NodeJS
export NODEJS_HOME=/{path_to_the_extracted_folder}/node-v15.6.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
Please make sure you change {path_to_the_extracted_folder} to the path where you extracted the compressed file in the previous step.
Finally you can click CTRL+C to exit nano, type y then click enter.
To refresh the profile file enter the below code
. ~/.profile
Finally
To make sure everything is working fine check the nodeJs version by entering this command node -v it has to print v15.6.0.
You will not have to worry about the previously installed node version since above steps will change the nodeJs path.

NPM install current application globally (e.g. npm install -g .)

I am working on a package that is mean to be used globally and I want to install it globally before publishing it.
I've tried to use npm i -g . but it always fails due to files not being found
npm ERR! code ENOENT
npm ERR! syscall access
npm ERR! path /home/ivan/lux2/cli/node_modules/file-uri-to-path
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, access '/home/ivan/lux2/cli/node_modules/file-uri-to-path'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ivan/.npm/_logs/2020-04-29T01_38_22_536Z-debug.log
I've tried this on a couple of different global npm package I'm working on all have the same result. I created a new package and it did work, is it something weird about the failing module (I've also seen bindings, nan and fsevents with this same error)
If I try creating those directories (they are not in my dependencies) I just end up finding more missing directories.
Any help would be appreciated.
Make sure you are running this command in a correct path and try to run command like this - npm install libraryName -g

I cannot create angular project with "ng new app_name". Get error -4058

When I execute the command ng new app-name I get error -4058.
When I run the same command opening cmd as administrator in the directory C: / Windows/system32 I have no problems when creating the project. But if I change the directory I have the same issue.
I suppose it must be a permissions problem but it is not solved by opening cmd as administrator.
The creation process is frozen in extract: rxjs: and after a long time I get the following error
npm ERR! path C:\Users\Usuario\proyectName\node_modules\#angular-devkit\build-optimizer\node_modules\typescript
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Usuario\proyectName\node_modules\#angular-devkit\build-optimizer\node_modules\typescript' -> 'C:\Users\Usuario\proyectName\node_modules\#angular-devkit\build-optimizer\node_modules.typescript.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Usuario\AppData\Roaming\npm-cache_logs\2018-03-20T02_40_45_377Z-debug.log
Error: Package install failed, see above.
Package install failed, see above.
Npm version
5.7.1
Angular version
Angular CLI: 1.7.3
Node: 8.10.0
OS: win32 x64
Angular:
...
I was able to solve the problem by uninstalling completely angular/cli and node
Uninstalling angular/cli and nodejs as administrator.
Delete folders from% appdata% (npm, npm-cache)
delete "nodejs" folder from Programs and Files
Reboot
Reintall lastest version node (not as administrator)
Install angular/cli (not as administrator)

Resources