errno: -4058, code: `ENOENT`, syscall: 'spawn npx', path: 'npx'

119 Views Asked by At

Issue

I am getting the runtime error shown in the title in a Git Bash terminal session when running an nx command.

Background

A Prisma nx-plugin has been installed. It works fine except that the prompt does not display when asking for a response from the user. So it appears as if the routine is frozen.

To resolve this problem the default executor routine has been modified.

However, when running the new executor it fails on the child.stdout.on() line with the runtime error shown in the title.

I am running: Windows 11 Home Edition

Code

import { PrismaExecutorSchema } from './schema';
import { spawn } from 'child_process';

export default async function runExecutor({
  _,
  schema,
  ...options
}: PrismaExecutorSchema) {

  // `inherit` allows the parent terminal to send and receive input and output on stdin/out/err.
  // This is necessary because prisma commands are interactive.
  const child = spawn(
    'npx',
    [
      'prisma',
      ..._,
      `--schema=${schema}`,
      ...Object.entries(options).map(([key, value]) => `--${key}=${value}`),
    ],
    {
      stdio: ['inherit', 'pipe', 'inherit'],
    }
  );

  // But we manually console.log stdout so that it flushes when waiting for stdin.
    child.stdout.on('data', (chunk) => console.log(chunk.toString()));

....

  return {
    success: true,
  };
}

Error

Below is the error that I am getting. This happens when the code attempts to execute line: child.stdout.on(...);

> nx run db:prisma migrate reset

node:events:492
      throw er; // Unhandled 'error' event
      ^
Error: spawn npx ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn npx',
  path: 'npx',
  spawnargs: [
    'prisma',
    'migrate',
    'reset',
    '--schema=packages/db/src/schema.prisma'
  ]
}
Node.js v18.17.1

Summary

From what I could find, this error means that it cannot find the path to my npx routine. However I have it installed and can run it from a Git Bash terminal. I even tried replacing npx with the full path: /c/Program Files/nodejs/npx and /c/Progra~1/nodejs/npx without any success.

So I am not sure why I am getting this error.

Again, your help is appreciated.

0

There are 0 best solutions below