Title: Issues running a next.js project on server
Tags: node.js;next.js
Question: 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 stefanie42@example.org._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?
Comment: 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


Here is another answer: 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:
&quot;scripts&quot;: {
&quot;test&quot;: &quot;jest --runInBand&quot;
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&amp;A with a lot of resources on this topic you can consult.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:11/16/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<node.js><next.js>', 'Title': 'Issues running a next.js project on server', 'ViewCount': 221, 'id': 69997166, 'user_AboutMe': None, 'user_AccountId': 23360583.0, 'user_DisplayName': 'PesceJonathan', 'user_Reputation': 21.0, 'user_Views': 0.0, 'user_id': 17432889.0}}