Browse by section

Web Design & Dev 日本語

npm run Errors: Fixing Them by Upgrading Node.js

Running npm run dev on a Nuxt starter template produced a warning and then an error instead of a dev server.

The short answer: the Node.js version was too old. Upgrading Node to an LTS release with n or nvm fixed it.

In my case I had deliberately downgraded Node to keep an old gulp 3.x setup working. Anyone who has pinned Node low for a legacy project and then tried to run something modern will land in the same state.

This article covers the two messages I saw and what to do about each today. The command I used at the time, npm config set scripts-prepend-node-path true, no longer exists in npm 7 and later — so that is covered too, to save anyone arriving here from typing it.

Sponsored

Check this first

Run node -v and npm -v. If Node is on an end-of-life release, most modern tooling will not run at all.

node -v
npm -v

Node.js support status as of September 2026:

▼Node.js versions

Version Codename Status
v26 — Current (not for production)
v24 Krypton Active LTS (recommended)
v22 Jod Maintenance LTS
v20 and below Iron and earlier End of life

Production projects should sit on Active LTS or Maintenance LTS. If node -v reports v20 or lower, that is very likely the cause.

The npm run warning

The warning asked me to enable an option called --scripts-prepend-node-path. It was npm asking whether to put the Node binary’s directory at the front of PATH when running scripts.

What worked at the time (npm 6 and earlier)

npm config set scripts-prepend-node-path true

Why you should not run that today

scripts-prepend-node-path was removed in npm 7 and does not exist in current versions. Setting it now does nothing except produce an unknown-config warning.

It does not appear anywhere in the npm 11 configuration reference. Which means seeing this warning at all is the real signal: the npm you are running is very old. npm ships with Node, so upgrading Node upgrades npm too.

To upgrade npm alone:

npm install -g npm@latest

That will not get you far while Node itself is out of date.

Sponsored

The npm run dev error

With the warning gone, npm run dev still failed. Node was on v11.15.0 — two major versions behind even at the time, and below what Nuxt required.

Upgrading Node.js

Use a version manager. On macOS, either n or nvm.

▼n and nvm compared

n nvm
Installation Via npm A shell script
Switching Replaces the system-wide Node Per shell session
Per-project pinning Not supported .nvmrc
Suits One version for everything Different versions per project

If you have a legacy project that forces an old Node, choose nvm. Switching per project means never forgetting to switch back — which is exactly how I ended up in this situation.

Upgrading with n

npm install -g n
sudo n lts

Use sudo n lts, not sudo n latest. latest installs the Current release, which is not intended for production work.

node -v

Upgrading with nvm

nvm install --lts
nvm use --lts

Put a .nvmrc at the project root and nvm use picks the right version automatically in that directory:

lts/krypton

An explicit version number works too. Committing this file is what stops “it works on my machine” from becoming a recurring conversation.

Preventing it from happening again

Declare the required Node version in package.json under engines, and installs on the wrong version will warn.

{
	"engines": {
		"node": ">=22.0.0"
	}
}

To make it a hard failure rather than a warning, add a .npmrc at the project root:

engine-strict=true

Version mismatches are frustrating mainly because the error messages rarely point at the cause. When a tool will not run, check node -v before anything else. In this case, doing that first would have solved it in one step instead of several.

If you are setting up the surrounding environment, installing Homebrew and Vim on a Mac covers PATH configuration and how to check it when something is not picked up.