Tommaso Orlandi
Tommaso Orlandi

Reputation: 53

Wrong Node.js version on Next.js

I am a relatively new to node.js and next.js and I just started a project on Next.js. As soon as I type

npm run dev

I get the following error:

You are using Node.js 18.12.1. For Next.js, Node.js version >= v18.17.0 is required.

First thing I automatically did was to update node. Now if I run

nvm list

I get the following

v14.17.6
       v18.17.0
        v21.6.0
->       system
default -> v21.6.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v21.6.0) (default)
stable -> 21.6 (-> v21.6.0) (default)

Correct me if I m wrong but it looks to me there are 3 node versions in my system and the default one is v21.6.0, the latest. I run

node -v

but I get

v18.12.1

which I don' t see in the list. Cool, no problem, let me type

nvm use 21.6.0

The message is pretty clear: Now using node v21.6.0 (npm v10.3.0)

Great, now let's run again

npm run dev

npm WARN cli npm v10.3.0 does not support Node.js v18.12.1. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

> [email protected] dev
> next dev

You are using Node.js 18.12.1. For Next.js, Node.js version >= v18.17.0 is required.

What am I supposed to do?I tried different things but I always get the same result.... Any idea?

EDIT:

Initially I thought there was an interference by these two lines (from FLY.io)

export FLYCTL_INSTALL="/home/tommaso/.fly" export PATH="$FLYCTL_INSTALL/bin:$PATH"

So I deleted fly from the system and got rid of those lines. ChatGPT told me to insert this line instead:

export PATH="/home/tommaso/.nvm/versions/node/v21.6.0/bin:/home/tommaso/.volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/sn>

Yet when I run echo $PATH the result is preceded by this line:

/home/tommaso/.volta/bin: (and the rest as above)

Now not only things are not fixed but when I run

npm run dev

I get the following:

npm WARN cli npm v10.3.0 does not support Node.js v18.12.1. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/tommaso/package.json
npm ERR! errno -2
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/home/tommaso/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: /home/tommaso/.npm/_logs/2024-01-23T23_22_43_070Z-debug-0.log

Upvotes: 2

Views: 4344

Answers (1)

Tommaso Orlandi
Tommaso Orlandi

Reputation: 53

At the end I made the classic mistake of not reading properly the PATH. I installed Volta in the past, I don' t even remember when and why, and that caused the whole issue. Volta apparently "keeps track of which project (if any) you’re working on based on your current directory. The tools in your Volta toolchain automatically detect when you’re in a project that’s using a particular version of the tools, and take care of routing to the right version of the tools for you."

This according to the website, for some reason it didn' t update the required version of node for my project

All I did then was type

volta install node

to install the latest version of node. I then ran

npm install

and had the following error:

npm install npm WARN tarball tarball data for streamsearch@https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz (sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QnoNsuc+VsExg==) seems to be corrupted. Trying again. npm WARN tarball tarball data for streamsearch@https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz (sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QnoNsuc+VsExg==) seems to be corrupted. Trying again. npm ERR! code EINTEGRITY npm ERR! sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QnoNsuc+VsExg== integrity checksum failed when using sha512: wanted sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QnoNsuc+VsExg== but got sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==. (5370 bytes)

npm ERR! A complete log of this run can be found in: /home/tommaso/.npm/_logs/2024-01-24T11_41_57_389Z-debug-0.log

that was easily fixed by clearing the cache via:

npm cache clean --force

Finally I ran again

npm install 

and everything seems working!

Upvotes: 2

Related Questions