构建 react.js/next.js 应用时未处理的"错误"事件



在本地服务器上构建是可以的,但如果我尝试在生产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托管受到40个服务器进程的限制。如果不使用typescript,那么您将出现类似于"sh:1:next:权限被拒绝";。