构建 react.js/next.js 应用程序时未处理的 'error' 事件

Unhandled 'error' event while building react.js/next.js app

在本地服务器上构建没问题,但如果我尝试在生产 linux 服务器上构建,则会出现错误:

> next build                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                            
info  - Loaded env from /home/*/*********/tech/public_html/.env.production                                                                                                                                                                                    
info  - Checking validity of types                                                                                                                                                                                                                          
node:events:504                                                                                                                                                                                                                                             
      throw er; // Unhandled 'error' event                                                                                                                                                                                                                  
      ^                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                            
Error: spawn /home/*/*********/tech/nodejs/bin/node EAGAIN                                                                                                                                                                                                    
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)                                                                                                                                                                             
    at onErrorNT (node:internal/child_process:478: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:289:12)                                                                                                                                                                             
    at onErrorNT (node:internal/child_process:478:16)                                                                                                                                                                                                       
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {                                                                                                                                                                                
  errno: -11,                                                                                                                                                                                                                                               
  code: 'EAGAIN',                                                                                                                                                                                                                                           
  syscall: 'spawn /home/*/*********/tech/nodejs/bin/node',                                                                                                                                                                                                    
  path: '/home/*/*********/tech/nodejs/bin/node',                                                                                                                                                                                                             
  spawnargs: [                                                                                                                                                                                                                                              
    '/home/*/*********/tech/public_html/node_modules/next/dist/compiled/jest-worker/processChild.js'                                                                                                                                                          
  ]                                                                                                                                                                                                                                                         
} 

已尝试重新安装 node_modules,清理缓存但没有任何变化。检查是否有一些未处理的错误。

package.json:

{
  "name": "*****",
  "version": "1.0.0",
  "description": "******",
  "main": "index.js",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "mysql": "^2.18.1",
    "next": "^12.1.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@types/mysql": "^2.15.21",
    "@types/node": "^17.0.21",
    "@types/react": "^17.0.40",
    "eslint": "^8.11.0",
    "eslint-config-next": "^12.1.0",
    "typescript": "^4.6.2"
  }
}

主要原因是Timeweb hosting 受限于40 个服务器进程。如果不使用打字稿,那么您将遇到类似“sh: 1: next: Permission denied”的错误。