NodeJS 在cpanel中运行jest-worker时出错(adonisjs + nextjs + reactjs)

1bqhqjot  于 2022-11-04  发布在  Node.js
关注(0)|答案(1)|浏览(171)

你好,我在cpanel中部署adonisjs + nextjs + reactjs时遇到了问题。我得到了如下的日志错误

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: spawn /opt/alt/alt-nodejs12/root/usr/bin/node EAGAIN
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'EAGAIN',
  code: 'EAGAIN',
  syscall: 'spawn /opt/alt/alt-nodejs12/root/usr/bin/node',
  path: '/opt/alt/alt-nodejs12/root/usr/bin/node',
  spawnargs: [
    '/home/test123/nodevenv/repositories/testproject/12/lib/node_modules/jest-worker/build/workers/processChild.js'
  ]
}

我的服务器.js

'use strict'

const { Ignitor } = require('@adonisjs/ignitor')

new Ignitor(require('@adonisjs/fold'))
  .appRoot(__dirname)
  .fireHttpServer()
  .catch(console.error)

我下一个配置js

'use strict'

const next = require('next')
const { withPlugins } = require('next-compose-plugins')
const withOffline = require('next-offline')
require('dotenv').config()

const nextWithOfflineConfig = {
    dontAutoRegisterSw: false,
    generateInDevMode: false,
    workboxOpts: {
        swDest: './next/.next/service-worker.js',
        runtimeCaching: [
            {
                urlPattern: /^https?.*/,
                handler: 'NetworkFirst',
                options: {
                    cacheName: 'https-calls',
                    networkTimeoutSeconds: 15,
                    expiration: {
                        maxEntries: 150,
                        maxAgeSeconds: 1 * 24 * 60 * 60, // 1 day
                    },
                    cacheableResponse: {
                        statuses: [0, 200],
                    },
                },
            },
        ],
        debug: false,
    },
}

const nextEnv = {
    env: {
        APP_KEY: process.env.APP_KEY,
    }
}

module.exports = withPlugins([
    [withOffline, { nextWithOfflineConfig }],
    [nextEnv]
])

软件包.json

"next": "^10.0.9",
"next-compose-plugins": "^2.2.1",
"next-offline": "^5.0.3",
"next-page-transitions": "^1.0.0-beta.2",
"next-pwa": "^5.2.21",
"react": "^17.0.2",

cpanel依赖项

node 12.22.9
npm 6.14.0

"我已经试过了“
rm -rf node_modules rm package-lock.jsonYarn.锁定npm缓存清除--强制安装npm
但仍然没有解决问题
有什么解决办法吗?

b09cbbtk

b09cbbtk1#

我猜你的服务器运行的是CloudLinux,因为这是这个错误通常出现的时候?
这是LVE中可以创建的进程和线程数量的限制。如果编辑next.conf.js并添加实验部分:

module.exports = {
  experimental: {
    workerThreads: false,
    cpus: 4
  }
};

这将禁用工作线程,并将CPU计数设置为4,以便限制创建的进程-您可能仍然需要根据运行构建的帐户内的限制进行调整。
你可以在我帮助一位客户解决了同样的问题后写的博客中读到更多关于它的信息:https://kdaws.com/2022/10/fixing-next-js-error-spawn-errno-11-on-cpanel-and-plesk-with-cloudlinux/
谢谢你,
卡尔

相关问题