I really messed up NPM - node.js

I think I really screwed up npm. So I tried to get gulp to work and it wasn't so I tried changing the route but by mistake I guess the article I was looking at was for mac and I have windows. Anyways I tried to do a solution and it was still working slightly at the time, so I opened up npm config edit and a file came up to change the prefix but when I did it, I accidentally just copied and pasted instead of putting my actually computer username and now npm wont work at all or even load anything and I am trying to relocate the file but I cant use npm now and I cant find the file.
I was using this to help me out npm - EPERM: operation not permitted on Windows

Found the answer.
You want to go to thisPC -> C: -> users -> \your computers username\ -> npmrc (NPM RC file), go into that file, go to prefix= (kind of at the top) and then fix the path. Thanks everyone!

Just uninstall and reinstall node entirely. It will be faster than attempting to fix this problem.

Related

When I try to execute 'npx create-next-app', the installation never ends

I'm trying to create a new NextJS app, but the command npx create-next-app <name> never ends. It installs a few files along the way (including node_modules/), then after a while, among all the great lines that a CMD shows, it displays an installation line that never ends. When I try to cancel the installation, I must restart my PC completely.
Note: the last line is always beginning with "reify:something: timing ... Completed in Xms"
My problem
I've tried to reinstall NodeJS, It did not change a single thing.
I've tried to delete the cache, nothing changed.
I have used npm in the past and it always worked fine, I have absolutely no idea why it doesn't work now.
Please help me, I don't know what to do, except to throw my PC out the window.
I'm on Windows 10, using npm 7.24.1 with node v14.17.6
Finally, I fixed my problem thanks to Marcel Herd: I installed WSL 2 and from now on I'll use Ubuntu on Windows to execute npm commands.
However, I have still no idea why I had to do such a thing...
Thank you
If you are interested, here are links that helped me:
https://learn.microsoft.com/en-us/windows/wsl/install
https://learn.microsoft.com/en-us/windows/wsl/setup/environment
https://learn.microsoft.com/fr-fr/windows/dev-environment/javascript/nodejs-on-wsl

strange npm problem, command never finishes, hangs forever

This is windows 10, node-v10.15.3-x64.msi install.
using either command prompt or power shell I type npm and nothing happens and it doesn't bomb or returns to the prompt. Just the little blinking dot that lies to me saying it is doing something. When I stop being fascinated by this blinking dot and hit control c it says Terminate batch job (y/n) ? y gives me back my prompt. Obviously there was some process running but I am not getting a functioning program. Any ideas? I know this is the head scratch kind of problem that does not usually get answered but I can't be so special nobody else has this happen.
What underlying tech does npm rely on? python?
Ok with help from the other thread I got it figured out.
Yes I screwed with prefix to my detriment. The reason why I kept going round and round deleting and reinstalling is I missed .npmrc in my user directory. The prefix in it was set to a path that no longer existed. I deleted my profile .npmrc and it started working again. I have now learned that is the file to edit to set prefix and cache.
Now the structure of the nodejs stock install for npm is bizarre imho. The npm executables are in the nodejs directory. Node itself is installed nodejs/node_modules/npm. The npm modules are path nodejs/node_modules/npm/node_modules.
Initially I changed my personal .npmrc to this contents
prefix="C:\Program Files\nodejs\node_modules\npm"
cache="C:\Program Files\nodejs\node_modules\npm"
This stopped npm from installing into my appdata/roaming directory but it kept bombing because it could not create the cache directories because it was in Program Files
But I was happy because it was trying to install global into one directory instead of my profile roaming. The main reason I started this odyssey is I wanted global modules in ONE location.
So what I did was moving nodejs from program files to another directory.
change my profile .npmrc to this
prefix="C:\nodejs\node_modules\npm"
cache="C:\nodejs\node_modules\npm"
changed the path entry for nodejs in paths in system properties / advanced / environmental variables / system variables / path to C:\nodejs.
I also keep deleting path in the top path in user variables but it seems to keep coming back like Freddy Krueger. Doesn't seem to do any harm now though.
A lot of examples try to set prefix to nodejs\npm. Maybe that was kosher at one time but now the npm executable called npm is in the nodejs root directory.
Okay I am not a tech writer but I hope this will provide clues to other clueless like me. Cheers!

NPM command config is broken

I edited npm config set <key> <value> and messed up.
Now whenever I try running anything that remotely starts with npm config, I'm getting an issue that looks like that:
Error: Failed parsing JSON config key
How can I reset my npm config or find the file to manually delete my changes?
I have tried reinstalling npm and nvm several times.
Accepted answer
Was technically correct, I also realized that I was missing a second question (ie how to find invisible files athe mac). I'm on a mac and .npmrc is a hidden file (which can be toggled with cmd+shift+.) But all in all, it worked out, thanks yall!
Try editing the config file directly: ~/.npmrc
https://npm.github.io/installation-setup-docs/customizing/the-npmrc-file.html

npm error on every command: EEXIST: file already exists, mkdir 'c:\users\user\appdata\Roaming\npm'

I'm just new to node and npm and this is frustrating.
Well it's almost all said in the title.
On a Windows 10 x64 using a NON elevated prompt, all npm commands shows:
EEXIST: file already exists, mkdir 'c:\Users\Josep\AppData\Roaming\npm'
at Error (native)
Even npm -v shows it twice before the version number.
Not hapening in an elevated prompt. version numbers differ in an elevated and a user prompt.
Double checked PATH variable. Same on two cmd windows.
Node version 6.10.0
NPM Versions: 4.3.0 at elevated prompt and 3.10.10 at a user prompt.
For me, just adding --force solved it.
I had similar issue, solved it by removing .npmrc file, located at c:\Users\<USER>\ location.
I believe it was caused by running earlier npm config set in wrong location.
Kudos to this comments thread.
In my case remove white space from folder name.
Try reinstalling node and npm for the non-admin account. If that's not an option, you can use the portable version:
Download from http://nodejs.org/dist/
Extract the archive.
Open cmd and cd to the extracted folder.
Run nodevars.bat.
It will set PATH and other things so you can now use node from this folder.
I also had this problem. Just delete npm folder, it will be created again. This problem is due to user privileges.
this is because you have same file in node_modules/Cypress/bin and node_modules/.bin, which is cypress(type=file).
Remove cypress(type=file) from node_modules/.bin, this will resolve the issue.
it happened to me, I had a space in my folders path C:\Users\Jhon Doe, should be C:\Users\JhonDoe.
Microsoft has a bit more information about how this can happen: https://learn.microsoft.com/en-US/troubleshoot/windows-client/user-profiles-and-logon/renaming-user-account-not-change-profile-path
For me, cd ios && pod install && cd .. fixed it.
I had the same issue and was able to resolve it on Windows by running the cmd prompt as Admin.
Go to the folder where you have installed Cypress. For example D:\cypressautomation --> then go to "node_modules" --> and then ".bin" folder. Here in this folder, if there is any file named "cypress", then just delete it (before deleting I think cypress needs to be closed). Reopen the cypress. This worked perfectly fine for me.
In my case. edid like below
※one more, check white space from folder name.

Installing Node.js (and npm) on Windows 10

I had some issues trying to install Node on Windows 10 and found the solution.
The error was as follows:
C:\Users\Stephan>npm
Error: ENOENT, stat 'C:\Users\Stephan\AppData\Roaming\npm'
The solution is below.
Edit:
It seems like new installers do not have this problem anymore, see this answer by Parag Meshram as my answer is likely obsolete now.
Original answer:
Follow these steps, closely:
http://nodejs.org/download/ download the 64 bits version, 32 is for hipsters
Install it anywhere you want, by default: C:\Program Files\nodejs
Control Panel -> System -> Advanced system settings -> Environment Variables
Select PATH and choose to edit it.
If the PATH variable is empty, change it to this: C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
If the PATH variable already contains C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm, append the following right after: ;C:\Program Files\nodejs
If the PATH variable contains information, but nothing regarding npm, append this to the end of the PATH: ;C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
Now that the PATH variable is set correctly, you will still encounter errors. Manually go into the AppData directory and you will find that there is no npm directory inside Roaming. Manually create this directory.
Re-start the command prompt and npm will now work.
go to http://nodejs.org/
and hit the button that says "Download For ..."
This'll download the .msi (or .pkg for mac) which will do all the installation and paths for you, unlike the selected answer.
In addition to the answer from #StephanBijzitter I would use the following PATH variables instead:
%appdata%\npm
%ProgramFiles%\nodejs
So your new PATH would look like:
[existing stuff];%appdata%\npm;%ProgramFiles%\nodejs
This has the advantage of neiter being user dependent nor 32/64bit dependent.
New installers (.msi downloaded from https://nodejs.org) have "Add to PATH" option. By default it is selected. Make sure that you leave it checked.
Everything should be installed in %appdata% (C:\Users\\AppData\Roaming), not 'program files'.
Here's why...
The default MSI installer puts Node and the NPM that comes with it in 'program files' and adds this to the system path, but it sets the user path for NPM to %appdata% (c:\users[username]\appdata\roaming) since the user doesn't have sufficient priveleges to write to 'program files'.
This creates a mess as all modules go into %appdata%, and when you upgrade NPM itself - which NPM themselves recommend you do right away - you end up with two copies: the original still in 'program files' since NPM can't erase that, and the new one inn %appdata%.
Even worse, if you mistakenly perform NPM operations as admin (much easier on Windows then on *nix) then it will operate on the 'program files' copy of NPM node_modules. Potentially a real mess.
So, when you run the installer simply point it to %appdata% and avoid all this.
And note that this isn't anything wierd - it’s what would happen if you ran the installer with just user priveleges.
You should run the installer as administrator.
Run the command prompt as administrator
cd directory where msi file is present
launch msi file by typing the name in the command prompt
You should be happy to see all node commands work from new command prompt shell
I had the same problem, what helped we was turning of my anti virus protection for like 10 minutes while node installed and it worked like a charm.
The reason why you have to modify the AppData could be:
Node.js couldn't handle path longer then 256 characters, windows tend to have very long PATH.
If you are login from a corporate environment, your AppData might be on the server - that won't work. The npm directory must be in your local drive.
Even after doing that, the latest LTE (4.4.4) still have problem with Windows 10, it worked for a little while then whenever I try to:
$ npm install _some_package_ --global
Node throw the "FATAL ERROR CALL_AND_RETRY_LAST Allocation failed - process out of memory" error. Still try to find a solution to that problem.
The only thing I find works is to run Vagrant or Virtual box, then run the Linux command line (must matching the path) which is quite a messy solution.
For me I had to delete the nodejs folder in \program files and then when I went to install through the msi it worked. Seemed like when I uninstalled Node it didnt actually delete this file
I had the same problem, but after trying everything on this post unsuccessfully, I just had to restart.
So if you haven't tried restarting the computer after the installation, try it.
Restart your computer after installation

Resources