2

I am currently trying to run a project (simple test project) of next.js on a Linux server. The project is able to run locally no problem, however every time I run npm run dev or npm run build I get the following error:

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: spawn /nfs/encs/ArchDep/x86_64.EL7/pkg/node-v16.13.0/root/bin/node EAGAIN
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -11,
  code: 'EAGAIN',
  syscall: 'spawn /nfs/encs/ArchDep/x86_64.EL7/pkg/node-v16.13.0/root/bin/node',
  path: '/nfs/encs/ArchDep/x86_64.EL7/pkg/node-v16.13.0/root/bin/node',
  spawnargs: [
    '/nfs/www/groups/h/hn_comp353_2/comp353/node_modules/jest-worker/build/workers/processChild.js'
  ]
}

Any idea on how to resolve this issue?

Martin Devillers
  • 17,293
  • 5
  • 46
  • 88
  • This is a tricky error that can have many causes. Please consult the following SO Q&A resource that has many links on the topics: https://stackoverflow.com/questions/27688804/how-do-i-debug-error-spawn-enoent-on-node-js – Martin Devillers Nov 18 '21 at 13:44

1 Answers1

3

I see in your spawnargs that it's trying to execute jest, so this failure has something to do with your Jest tests not being able to run on your Linux server. This may be caused by Jest trying to spawn more threads than there are resources available on your server. This is pretty common on heavily virtualized environments where the resources are limited.

Can you try running Jest with either the --runInBand or --maxWorkers=2? If you're running Jest through npm you'll have to add the command in your package.json like this:

{
  "scripts": {
    "test": "jest --runInBand"
  }
}

As a general remark, NodeJS Error: spawn errors are tricky to debug and can be caused by a variety of issues. There's another SO Q&A with a lot of resources on this topic you can consult.

Martin Devillers
  • 17,293
  • 5
  • 46
  • 88