"No version is set for command npm" .tool-versions file missing - node.js

I'm attempting to create my react app in VS code. After installing node.js (V 18.12.1), I ran the code to create my app and recieved the following response:
npm create-react-app example
No version is set for command npm Consider adding one of the following versions in your config file at nodejs 16.15.0 nodejs 16.17.0 nodejs 16.17.1 nodejs 16.18.0 nodejs 16.18.1
I attempted the reinstall node.js and believe the issue may be due to the absence of my .tools-version file, but I don't know how to create it.

You can use this
npx create-react-app example
Can see the detail in official document.

This could be because you are using a version of Node.js that does not include the npm command. In this case, you can try installing the npm command by running the following command:
npm install -g npm
or try these.
Verify that Node.js is installed correctly on your system by running the node -v command in a terminal. This should print the version number of Node.js if it is installed correctly.
Check if the npm command is in your system's PATH by running the
which npm command in a terminal. This should print the full path to the npm executable if it is in your PATH.
If npm is not in your PATH, you can add it by modifying your PATH
environment variable. You can do this by modifying your shell's
profile file (e.g., ~/.bashrc, ~/.bash_profile, etc.), or by adding the path to the npm executable to your PATH manually.
If you have multiple versions of Node.js or npm installed on your
system, you may need to update your PATH to point to the correct
version. Alternatively, you can use a version manager such as nvm
(Node Version Manager) to manage multiple versions of Node.js and
npm on your system.
Try out and see!

Came here searching a very similar error. I had just got setup with a version manager, asdf, and installed NodeJS LTS (asdf install nodejs lts) before running an npx command and getting the error below.
No version is set for command npx
Consider adding one of the following versions in your config file at
nodejs 18.12.1
nodejs lts
There's no path at the end of that second line 🤔 but given the error and asdf instructions on setting a version, I configured a NodeJS version in the global .tool-versions file and that solved my issued:
echo "nodejs lts" >> $HOME/.tool-versions
Manu Jo Varghese has some great suggestions for checking your installation and environment! To add:
which node: find NodeJS program in your path
bash or zsh -> check which shell you're in, then check .bashrc or .zshrc files as fits

Related

How Can Knex (or Any NPM Package) Run a Different Version of Node?

I'm trying to use Knex's seed:run command (ie. npx knex seed:run), and inside my seed file I've added this line, which logs the version of Node that it's being run with:
console.log(process.version);
Now, if I run that exact same line of code in the Node command prompt itself (node), I get:
v14.2.0
Similarly, when I run node --version it correctly returns v14.2.0.
However, when Knex runs my seed file, I instead see:
v11.15.0
Can anyone explain how/why Knex is using a different version of Node, and how I can make it stop?
P.S. I've tried wiping my node_modules folder out and re-installing via npm i, but Knex continues to use an old Node somehow. Knex itself is installed at the latest version (0.21.1).
This may happen if you have a global installation that runs in privileged account (root), and a local installation to current user.
It is possible you are using some node versioning tool to manage nodejs versions, it creates a symbolic link to a managed version of node that overrides the default configuration. There are many tools that does that like nvm, n.
Danizavtz's answer didn't solve thigns for me, but it did point me in the right direction. I realized that I did have two versions of Node: one installed by Linux (using apt-get), and one I'd installed myself (to get a newer version of Node).
The solution for me was to remove the system version of Node with:
sudo apt-get remove node
That left me with a working Node ... but it removed my npm. I guess I could have just re-installed everything, but since I already had node and just needed npm, I downloaded the latest Node installation and used the node in it to install npm. I did this both with and without sudo (I'm not sure if doing it without sudo was even necessary, as it didn't fix things):
sudo ~/node-v14.3.0-linux-x64/bin/node ~/node-v14.3.0-linux-x64/bin/npm i -g npm
After that I finally got the expected Node version when I ran npx/npm!

Node Modules not Found Even Environment is Configured

I am installing nodeJS v10 in Windows 10 Pro, After downloading the installer and install, I can run npm and npx to install the node modules but the installed global command cannot be found. I also try to use back npm install -g, but the error stays the same. Saying react-create-app, I can see it is being installed in the specified directory, but it always report command not found.
Command not found
npm config get prefix
Actual directory
Environment variable settings
User Variables
System Variables
As the environment variable seems setting up correctly, it is so weird for not finding the command. Any help would be appreciated, thank you very much

Problem re-installing NodeJS and NPM on Windows10

I am a novice with node.js and npm. I wanted to use purgecss npm plugin so tried to update and upgrade my node
Downloaded v11.1 and installed it but after that Its broken now and I can't figure out its log file either
Here is the npm-debug.log file with it. Please tell me in simple and plain words how to fix this node installation problem
If your having a problem try to update node.js (I did for 3 days). Try Give NVM (Node Version Manager) a try.
Do the following in this order:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
command -v nvm
nvm install node
node -v
node -v will show you that your node.js is updated.
So the problem was that the Environment Paths somehow got messed up on the re-install of Node latest version.
So these are the Environment Variables paths settings that worked for me
Now my settings that worked for me looks like this
USER VARIABLES
SYSTEM VARIABLES

Node.js with Npm standard installation vs global installation of Npm

I've installed node.js v8.11.3 from their website, and it comes with npm v5.6 built-in.
Those files are in my "program files\nodejs" folder.
But recently I got aware that I can run:
npm install -g npm #"some version (upgrade or downgrade)"
and another version will be installed globally and those files will by in my "%appdata%\npm\node_modules\" folder.
Question1:
If I do this, what happens when I run the next npm command on VSCode Terminal? Which version would I be using then? Will the global version override the buil-in version?
Question 2:
And also, what happens if I install npm locally in one of my projects? Does the local version alsos override the built-in version? Does it override any global version as well?
Question 3:
It feels weird to use npm to install npm. Is this common?
Thanks.
Question 1: If I do this, what happens when I run the next npm command on VSCode Terminal? Which version would I be using then? Will the global version override the built-in version?
When you install software on Windows and attempt to use a command from the console, it takes the name of the command you're running and looks in your Windows' PATH Environment Variable for the list of folders to look for when you run a command. If you were to run npm install -g npm like you said, the version of NPM you ran when it came to your terminal would be the first version that appears in your PATH Environment Variable.
Question 2: And also, what happens if I install npm locally in one of my projects? Does the local version also override the built-in version? Does it override any global version as well?
Since your PATH Environment Variable likely doesn't extend to the node_modules folder in your project, it likely wouldn't change anything. Locally installed node modules are local in nature, meaning they rarely interact with anything outside of their folder, they have to be called.
Question 3: It feels weird to use npm to install npm. Is this common?
I can't say it is common. I doubt most node developers install npm on its own very often. And if they do, they likely don't do it through an already working npm. However, you can update all of your installed packages through npm, including npm itself, using npm update.
Basically according to the doc i would have one answer for the two questions :
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
the doc here

Global Node Packages Installed to Wrong Directory

I'm trying to install Hexo globally using npm. When I run
npm install -g hexo-cli
I'm informed that it was installed to /Users/myusername/.node/bin/hexo -> /Users/myusername/.node/lib/node_modules/hexo-cli/bin/hexo
The problem comes in when I run hexo init blog and the hexo command is not found.
I installed Node and npm with Homebrew, so when I run which node and which npm, the results are /usr/local/bin/node and /usr/local/bin/npm respectively.
I'm thinking that I still have leftover files and directories from when I installed Node without homebrew, but I don't want to start deleting things without fully knowing the repercussions. Would I be safe to delete all files located in the /Users/myusername/.node/ directory? I can't figure out why npm is not installing to the proper directory.
After a little digging, I found that my npm prefix variable was pointing do the wrong directory, left behind by the old Node installation. I ran npm config get prefix to see where it was pointing.
I set the new prefix value using npm config set prefix /usr/local. Homebrew is symlinked with this directory via /usr/local/bin. I uninstalled hexo-cli and reinstalled through npm, and now it works perfectly.
For NVM users
Run nvm use --delete-prefix v10.13.0 --silent replacing v10.13.0 with whatever version of node you're using.
A simple way to cope with environment variables/path problems on Windows:
Run command:
npm install -g hexo
Using node.js command prompt rather than cmd windows provided by Windows itself.

Resources