Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

594
Visualizações
nodejs child process - Error: spawn node ENOENT

I'm using this code to try spawn a child process that needs to run a script.

const child = require('child_process').spawn;
const path = require('path');
const script = path.format({dir: __dirname, base: 'myscript.js'});

    child('node', [script], {
        cwd: __dirname,
        env: {
            TEST_USERNAME: 'myuser',
            TEST_PASSWORD: 'mypassword'
        }
    }).on('error', (error) => {
        console.log(error);
    });

I'm getting this error when I try to run my index.js script

Error: spawn node ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:276:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node',
  path: 'node',
  spawnargs: [ '/Users/dev/Desktop/cli-training/demo.js' ]
}

UPDATE

I'm trying to run the child script after that inquirer.js have prompted some questions to the user. Can be this the problem?I've noticed that the child process will be not executed. Inside my child script I have this code

const { IgApiClient } = require('instagram-private-api');
const chalk = require('chalk');

console.log(chalk.magenta('Starting child script'));

const ig = new IgApiClient();

console.log(process.argv);

How I can fix it?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you want to execute the node binary in a child-process, it s better to refer to its full path, you can find it with process.execPath

this should fix your problem

child(process.execPath, [script], {
        cwd: __dirname,
        env: {
            TEST_USERNAME: 'myuser',
            TEST_PASSWORD: 'mypassword'
        }
    }).on('error', (error) => {
        console.log(error);
    });
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda