It is my understanding that npm gets installed alongside node when I use the node installer in Windows 10, and will be located in "D:\Program Files (x86)\nodejs" (I installed the 32 bit version to my D drive, C is my primary OS drive).
However, "npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently C:\Users<username>\AppData\Roaming\npm)." - https://docs.npmjs.com/try-the-latest-stable-version-of-npm
Initially, after I first installed nodejs, my Roaming/npm folder was empty since I did not install any packages globally. Afterwards, I wanted to upgrade my npm so I ran the following command - "npm i -g npm". This added the following items to my Roaming/npm folder.
Roaming/npm
Now, when I run npm -v, the updated version is shown (7.24.2).
My questions are:
1.) Since I only updated the global ( -g ) installed one ( %appdata%\npm\ ), the npm in "D:\Program Files (x86)\nodejs" should remain as the old version right? (6.4.13).
2.) If so, why is the newer version being used, if (refer to below)
According to https://docs.npmjs.com/try-the-latest-stable-version-of-npm, "it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm#." This does not seem like the case for me.
I did a "echo %PATH%" in cmd and I have confirmed that "D:\Program Files (x86)\nodejs" is indeed placed before "C:\Users<username>\AppData\Roaming\npm". So why is the newer version being used instead?
I tried to open cmd in "D:\Program Files (x86)\nodejs" and ran ".\npm.cmd -v" and it still gave me the same result which I was not expecting (7.24.2). I looked at the date modified for the nodejs folder and it does not seem like any changes were made.
Another thing I tried was logging in as a different user on my PC and running "npm -v", when I did that, it was showing the old version (which is what I expected since npm was only updated for my admin account, (admin\Appdata\Roaming\npm). So why is it that when I'm logged in as admin, it seems like the npm in "D:\Program Files (x86)\nodejs" is updated as well?
Any help to enhance/correct my understanding would be greatly appreciated, I am still quite new to npm and node.
Update: I am aware that nvm exists. This question is asking about the behaviour mentioned above.
Related
Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.
Every time I try to run npm on Windows 10, I get Error: EINVAL: invalid argument, mkdir 'C:\Program Files\nodejs"'
I have deleted %Appdata%\npm and %Appdata%\npm-cache.
I have deleted c:\program files\nodejs, checked that c:\program files (x86)\nodejs does not exist, and tried to install NodeJS in c:\nodejs instead to get rid of the space in the directory name.
I have uninstalled NodeJS and searched through the Windows registry, removing every reference to NodeJS.
I have tried to use NPM to update NPM to a different version, but I only get the same error.
I have removed all references to Node folders from environment variables and paths.
Of NodeJS versions I have tried Latest LTS Version: 12.16.3 (includes npm 6.14.4), and Latest Current Version: 14.2.0 (includes npm 6.14.4).
I have tried using Chocolatey to install NodeJS, it made no difference.
Every time I reboot, reinstall NodeJS, and try to use NPM, I get the same error.
When I try to check what version of NPM is actually installed, the answer is ... the same error.
How do I eradicate all NodeJS and NPM related files and settings from Windows 10 so that I can perform an actual clean install, without having to resort to the nuclear option, formatting the drive and reinstalling Windows?
Ok, after ripping my hair out, as well as half of the installed software on my PC, I continued googling, and eventually stumbled on the solution by investigating some file paths mentioned in this question: nodejs npm global config missing on windows.
Apparently, there is a config file %userprofile%\.npmrc which is relevant somehow. On my own computer, this file contained the text prefix=C:\Program Files\nodejs".
If that looks familiar, it's because it's the string in the error message that has been plaguing me. When I emptied the file, npm started working again, just like that.
I am following the following guide from GitHub Here but when I enter npm init I keep getting the error:
Sorry, there's a problem with nodist. Couldn't resolve node version
spec %s: %s 11.13.0 Couldn't find any matching version
I have followed the previous steps and set the version to v10.15.3, but the error keeps appearing every time I use nvm. I have also set the version to v11.13.0, as this is what the error is requesting, but I still get the same result. Installed versions include: 11.13.0, 10.16.0, 10.15.3, 8.11.2, 0.12.0
Any help with this would be much appreciated!
There are several reasons which can cause this problem:
If due to some reasons like poor internet connection your node or npm versions you have downloaded are corrupted. In this case you need to remove the files .npm-version-global and .node-version-global as well as empty the folders v, v-64 and npmv within the installation of the Nodist folder.
You have a local version of the node specified in .node-version file in the root directory of your project. In this case you need to install that version by nodist local XXX where XXX is the version of the node in .node-version file.
In my case, the problem was that I had a node version specified in my code repo that didn't match the node version installed on my machine. I needed the updated node version on my machine, so
I opened file explorer to the root of my repo.
I opened .node-version and edited the version number to the updated version I needed.
npm cache clean --force to start with a fresh cache. (Note: Others have said that npm cache clean --force is outdated, but this command worked for both my teammate and for me using npm version 6.9.0.)
npm install to reinstall my node modules.
npm run build and I had a clean build. Yay!
For Node 18 and npm 8.19.1, I found the advice at https://github.com/nullivex/nodist/issues/252#issuecomment-1170897428 useful.
I was getting cb.apply errors, and problems with #npmcli/arborist and libnpmfund, but I created those two links from the list.
I was using npx. This installs an old (v 5.8) version of npm inside its node_modules. That npm contains graceful-fs inside its node_modules. The cb.apply error was coming frome graceful-fs's polyfill.js.
I installed the latest version of graceful-fs, and copied the newer polyfill.js into the abovementioned (child of npm's) graceful-fs. This seemed to fix the problem for me.
I'm in a subfolder (D:\Alex\Desktop\Git\project), but even in that directory, running npm list says that there's no such project in D:\Alex\Desktop. I also can't install node_modules because none of the npm commands know the actual folder I'm in. I haven't run into this issue at all before, any ideas?
Suggested Info to Gather (and add to your post):
What version of Windows is installed (likely not the issue, but there are some known issues associated with Windows 7)?
What version of Node.js is installed (Use: node -v to check)?
What version of NPM is installed (Use: npm -v to check)?
When Node.js is installed using the Microsoft Windows installer package (.msi) download, NPM will also be installed, but the version lags behind the latest. So, for example, if you install the current LTS version of Node.js (6.11.3), NPM will be at version: 3.10.10, whereas the latest version of NPM is: 5.4.2.
Based upon your description of the problem, I am guessing that your version of Node.js is current (or fairly close), but that your version of NPM may be a bit out of date. Older versions of NPM would commonly generate a confusing and misleading error message associated with local modules that did not contain a package.json file; so running npm ls would produce error output similar to:
npm ERR! error in D:\Alex\Desktop\Git\project: ENOENT: no such file or directory
If I have guessed correctly, you should be able to resolve the problem by creating a package.json file in the D:\Alex\Desktop\Git\project directory using one of the following options:
Open a command prompt terminal window in the: D:\Alex\Desktop\Git\project directory/folder, run: npm init, and provide answers to the question prompts.
Open a command prompt terminal window in the: D:\Alex\Desktop\Git\project directory/folder and run: npm init --yes (which will suppress the prompts and apply default values).
Use a text editor to paste the following drop-in values into: D:\Alex\Desktop\Git\project\package.json, which declares the 2 required values: "name", "version", and includes a "description" because if there is no "description" field in the package.json, NPM uses the first line of the README.md or README (and your project may not include either):
{
"name": "my-desktop-git-project",
"version": "1.0.0",
"description": "Alex's Desktop Git Project"
}
Node noob here.
I had previously installed both npm and node separately.
Apparently, npm comes with node now. (link)
To my newbie mind, this means my previous dual installation is old and ugly. 1 binary > 2 binaries. So i uninstalled both.
Then I installed the latest node following the procedure. (i am running eOS)
Terminal
user#box:-$ which node
/usr/bin/node
user#box:-$ node -v
v0.10.22
user#box:-$ which npm
user#box:-$ npm -v
bash: /usr/bin/npm: No such file or directory
I can always run:
curl https://npmjs.org/install.sh | sh
but that seems to indicate that npm is actually NOT included in node.
When they say they are included do they just mean the code is in the same repo, but the binaries are still different?
Final question I have /usr/bin/node as well as /usr/bin/nodejs
can i delete one of these? im not sure when/where i picked up a second copy.
Yes, the nodejs package includes both node and npm executables. The code for each has its own repo, but when packaged both are included.
npm source: https://github.com/isaacs/npm
node source: https://github.com/joyent/node
When you install that .deb file from the PPA, you should get both /usr/bin/nodejs and /usr/bin/npm and 2 symlinks at /usr/bin/node (which points to) /etc/alternatives/node (which points to /usr/bin/nodejs).
If any of this isn't true, your install didn't fully succeed, most likely due to conflicting files you left around from your manual install. I would suggest uninstalling the .deb then making sure there are no stale files left from your manual install and then installing again.
Only node.js packages comes with npm. so if you are installing using an .msi, .exe, .dmg .pkg, .deb or using a package installer like apt-get, yum or brew, then you'll have both node and npm.
However,npm is not part of the node core. if you are installing node and using a method where you are using ./configure or make install || make link, then npm will not be installed, and will need to be compiled using the same type of installation, and node will have to be placed on your path.
If you used git, or unzipped node and you can see a configure script, then you will also need to acquire npm.
I've had issues (mostly on Mac) with npm ending up in directories that aren't in the terminal PATH. If you can figure out where npm is located, you can just add it to your path with something like:
export PATH=$PATH:/path/to/npm
I think (I'm not on a mac so I can't check at the moment) that it sometimes gets put in /usr/local/share/. But at any rate, the problem is likely NOT that npm isn't installed, but that it's installed somewhere you're not expecting.
Few months ago i had started learning the react so all this stuff i needed to install my laptop that had the ubuntu operating system.
What i did -- First i installed the node and without knowing that it came up with the npm package. I installed the npm package again.. but there was no conflict at all.
But after exploring all these things that nodejs have npm package. So i uninstalled the npm package due to concern about memory usage..
And Now everything is working fine....