Application React/nextjs on Cpanel server with Nodeselector does not run

Asked

Viewed 58 times

0

I am creating a React/nextjs application and deploying it on a Node Cpanel server (Node is through modpassenger and cloudlinux nodejs selector), I can install the dependencies normally using the npm install.

When I turn the remote npm build, i get the following error

      throw er; // Unhandled 'error' event
      ^

Error: spawn /opt/alt/alt-nodejs14/root/usr/bin/node EAGAIN
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -11,
  code: 'EAGAIN',
  syscall: 'spawn /opt/alt/alt-nodejs14/root/usr/bin/node',
  path: '/opt/alt/alt-nodejs14/root/usr/bin/node',
  spawnargs: [
    '/home/topensino/nodevenv/nextapp/14/lib/node_modules/jest-worker/build/workers/processChild.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/topensino/.npm/_logs/2021-01-27T15_38_34_096Z-debug.log

By examining the generated log it always looks like this

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/opt/alt/alt-nodejs14/root/usr/bin/node',
1 verbose cli   '/opt/alt/alt-nodejs14/root/usr/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 warn lifecycle The node binary used for scripts is /home/topensino/nodevenv/nextapp/14/bin/node but npm is using /opt/alt/alt-nodejs14/root/usr/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
8 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~build: PATH: /opt/alt/alt-nodejs14/root/usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/node-gyp-bin:/home/topensino/nextapp/node_modules/.bin:/home/topensino/nodevenv/nextapp/14/bin:/opt/alt/alt-nodejs14/root/usr/bin:/home/topensino/nodevenv/nextapp/14/lib/bin/:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin:/opt/cpanel/composer/bin:/home/topensino/.local/bin:/home/topensino/bin
10 verbose lifecycle [email protected]~build: CWD: /home/topensino/nextapp
11 silly lifecycle [email protected]~build: Args: [ '-c', 'next build' ]
12 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
13 info lifecycle [email protected]~build: Failed to exec build script
14 verbose stack Error: [email protected] build: `next build`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/opt/alt/alt-nodejs14/root/usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/index.js:332:16)
14 verbose stack     at EventEmitter.emit (events.js:315:20)
14 verbose stack     at ChildProcess.<anonymous> (/opt/alt/alt-nodejs14/root/usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/lib/spawn.js:55:14)
14 verbose stack     at ChildProcess.emit (events.js:315:20)
14 verbose stack     at maybeClose (internal/child_process.js:1048:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
15 verbose pkgid [email protected]
16 verbose cwd /home/topensino/nextapp
17 verbose Linux 4.18.0-147.8.1.el7h.lve.1.x86_64
18 verbose argv "/opt/alt/alt-nodejs14/root/usr/bin/node" "/opt/alt/alt-nodejs14/root/usr/bin/npm" "run" "build"
19 verbose node v14.15.1
20 verbose npm  v6.14.8
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] build: `next build`
23 error Exit status 1
24 error Failed at the [email protected] build script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

I can only run his build through the nodejs selector, using the build script, but on the command line of this error above, when I run the start command it shows that the server is working, but on port 3000 (which is not the right port for the application to run and be exposed to web requests).

Then following the next documentation, I created a custom server file, so that it can receive the connections on another port (no need to specify the port, since the initial nodejs script does not specify port and works normally)

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {
    // Be sure to pass `true` as the second argument to `url.parse`.
    // This tells it to parse the query portion of the URL.
    const parsedUrl = parse(req.url, true)
    const { pathname, query } = parsedUrl

    if (pathname === '/a') {
      app.render(req, res, '/a', query)
    } else if (pathname === '/b') {
      app.render(req, res, '/b', query)
    } else {
      handle(req, res, parsedUrl)
    }
  }).listen()
})

When I give an npm start, I get only aborted

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.