1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[ReactJS]

Discussão em 'Mobile' iniciado por Stack, Janeiro 27, 2021.

  1. Stack

    Stack Membro Participativo

    Estou criando uma aplicação react/nextjs e implantando ela em um servidor CPanel com node (o node é através do modpassenger e cloudlinux nodejs selector), consigo instalar as dependências normalmente usando o npm install.

    Quando rodo o comando npm build, eu recebo o seguinte erro

    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! nextapp@1.0.0 build: `next build`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the nextapp@1.0.0 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


    Examinando o log gerado ele sempre fica assim

    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 npm@6.14.8
    3 info using node@v14.15.1
    4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
    5 info lifecycle nextapp@1.0.0~prebuild: nextapp@1.0.0
    6 info lifecycle nextapp@1.0.0~build: nextapp@1.0.0
    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 nextapp@1.0.0~build: unsafe-perm in lifecycle true
    9 verbose lifecycle nextapp@1.0.0~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 nextapp@1.0.0~build: CWD: /home/topensino/nextapp
    11 silly lifecycle nextapp@1.0.0~build: Args: [ '-c', 'next build' ]
    12 silly lifecycle nextapp@1.0.0~build: Returned: code: 1 signal: null
    13 info lifecycle nextapp@1.0.0~build: Failed to exec build script
    14 verbose stack Error: nextapp@1.0.0 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 nextapp@1.0.0
    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 nextapp@1.0.0 build: `next build`
    23 error Exit status 1
    24 error Failed at the nextapp@1.0.0 build script.
    24 error This is probably not a problem with npm. There is likely additional logging output above.
    25 verbose exit [ 1, true ]


    Só consigo rodar o build dele através do nodejs selector, usando o script de build, mas na linha de comando da esse erro acima, quando rodo o comando start ele mostra que o servidor está funcionando, porem na porta 3000 (que não é a porta correta para a aplicação rodar e ser exposta a requisições web).

    Então seguindo a documentação do next, criei um arquivo de servidor customizado, para que ele possa receber as conexões em outra porta (não é necessário especificar a porta, já que o script inicial do nodejs não especifica porta e funciona normalmente)

    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()
    })


    Quando dou um npm start, recebo apenas aborted

    Continue reading...

Compartilhe esta Página