Skip to content
Nilay Kabariya

Entry No.072·Fixes·Updated ·3 min read

npm error code ENOENT, and spawn npx ENOENT on Windows

Read the path line first. On Windows, spawn npx ENOENT has a twist: adding .cmd now fails with EINVAL. Four ENOENT causes reproduced, each with its fix.

The error, verbatim

Jump to the fix ↓
npm error code ENOENT
npm error syscall open
npm error path D:\projects\app\package.json
npm error errno -4058
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'D:\projects\app\package.json'
✓ Reproduced on Windows 11 Pro; Windows Server 2025 (GitHub Actions)

Tested on

Node / npm
24.14.0 / 11.9.0
Re-run
November 3: Node 24.22.2, npm 11.19.1, cross-spawn 7.0.6 on Windows Server 2025
OS
Windows 11 Pro; Windows Server 2025 (GitHub Actions)
cross-spawn
7.0.6
Contents
  1. 1. Could not read package.json01
  2. 2. spawn ENOENT02
  3. 3. A file: dependency that doesn’t exist03
  4. 4. A script calls a missing file04
  5. What I ran it on05

The confusing one is on Windows: Error: spawn npx ENOENT, with npx installed and working in the terminal. npx is a .cmd file there, Node’s spawn doesn’t add the extension, and the old workaround of spawning npx.cmd now fails with spawn EINVAL on current Node. ENOENT itself just means “no entry”: a file or folder that doesn’t exist, named on the path line. Four situations produce it:

What you see Cause
syscall open, path ends in package.json You’re in the wrong folder
Error: spawn npx ENOENT (or spawn git, spawn python…) A script starts a program Node can’t find
Cannot find module after a clean npm install A file: dependency points at a missing folder
Cannot find module 'D:\…\scripts\build.js' A script calls a file that isn’t there

1. Could not read package.json

The most common one. Running npm install or npm run dev in a folder without a package.json gave:

npm error code ENOENT
npm error syscall open
npm error path D:\nk-enoent\c1\package.json
npm error errno -4058
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'D:\nk-enoent\c1\package.json'

The path is where npm looked. Usually the project is one level down, the folder a git clone or create-* command just made.

Check where you are and whether that folder has a package.json:

Get-Location; Test-Path package.json

If it prints False, cd into the project folder (the one with package.json) and run the command again.

If a package.json exists higher up, npm uses that one instead and you get Missing script rather than ENOENT (that error, explained).

2. spawn ENOENT

A script or tool tries to start another program and Node can’t find it. For a program that isn’t installed:

Error: spawn git-lfs-nope ENOENT

On Windows there’s a trap. npx, npm and most Node CLIs are .cmd files, and Node’s spawn doesn’t add .cmd for you:

Error: spawn npx ENOENT

Adding .cmd doesn’t help on current Node. spawn('npx.cmd', …) failed straight away with spawn EINVAL: Node refuses to run .cmd and .bat files without a shell since a 2024 security fix.

If you’re writing the code, run it through the shell as one command string:

spawn('npx --version', { shell: true, stdio: 'inherit' });

Or use cross-spawn, which handles Windows for you:

const spawn = require('cross-spawn');
spawn('npx', ['--version'], { stdio: 'inherit' });

If it’s someone else’s tool, install the program it names (git, python…) or update the tool.

3. A file: dependency that doesn’t exist

"mylib": "file:../mylib" in package.json, with no mylib folder there. npm install didn’t complain at all: it printed added 1 package and exited 0. It had created a link to a folder that doesn’t exist, and the failure came later, at run time:

Error: Cannot find module 'mylib'

Check that every file: path in package.json points at a real folder (relative to the package.json), fix the path or create the folder, then install again:

npm install

4. A script calls a missing file

"build": "node scripts/build.js" with no scripts\build.js:

Error: Cannot find module 'D:\nk-enoent\c3\scripts\build.js'
  code: 'MODULE_NOT_FOUND',

The script’s path is relative to the folder you run npm run from. Check the file exists at that path, or fix the path in the script.

What I ran it on

Windows 11 Pro, Node 24.14.0, npm 11.9.0, October 18, 2026, each case in a new folder. The spawn cases ran with Node’s child_process.spawn and spawnSync, and with cross-spawn 7.0.6. Every message above is the real output.

On November 3, 2026 the four cases ran again on a clean Windows Server 2025 machine (GitHub Actions windows-latest). npm install in a folder without package.json gave syscall open and the missing path; spawn('npx') gave spawn npx ENOENT, spawn('npx.cmd') gave spawn EINVAL, and both shell: true with a command string and cross-spawn printed npx’s version, while shell: true with an argument list still printed the DEP0190 warning; the file: dependency to a missing folder again installed with exit code 0 and failed only at require; and a script calling a missing file failed when run. The script and the run are public.

— N.K., end of entry No.072

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.034

    Fix: npm error Missing script: "dev" (and "start")

    npm can't find the script you asked for. Six real causes, from a stray package.json up the tree to monorepos, and two commands that show which one you have.

    > npm error Missing script: "dev"

    FIXED5 min
  2. No.093

    Fix: bigint Failed to load bindings, pure JS will be used

    bigint: Failed to load bindings, pure JS will be used. Why npm 12 shows it on every install, whether it matters, and how to get the native build back.

    > bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)

    FIXED3 minWindows
  3. No.071

    Fix: JavaScript heap out of memory (Node.js, tested)

    FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory. Default limits measured, and two ways the usual fix silently fails.

    > FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

    FIXED2 minWindows
  4. No.069

    Fix: EBUSY: resource busy or locked (npm, Windows)

    npm install and Node fail on Windows with EBUSY: resource busy or locked, rmdir. Reproduced: what holds the folder, how to find it, and why retrying fails.

    > npm error code EBUSY

    FIXED3 minWindows

Post card · Every Sunday

What broke this week.

One email on Sundays: the Node, TypeScript, Python and AI SDK releases that broke builds that week, each one reproduced, with a link to the fix that worked. Never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text