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

183
Visualizações
make-runnable package for ESModule NodeJS

make-runnable package works only on CommonJS, and base on this rules of import-export in CommonJS and ESModule :

https://miro.medium.com/max/875/1*3cI3YvzG0HakM7VCaxtbfA.png

I can not figure how to solve this my apps.

...

I am currently work on ESModule, so I need all of my code in modules type.

Here is my code on the file who need to import .mjs file:

const students = require('../../repository/students.mjs')

function drop() {
    students.drop()
}

module.exports = {
    drop
}

require('make-runnable/custom')({
    printOutputFrame:false
})

And when I run node path/to/my/file/index.js drop, this is the error ouput:

node:internal/modules/cjs/loader:979
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module my/path/to/api/controller.mjs not supported.
Instead change the require of my/path/to/api/controller.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (my/path/to/index.js:1:18) {
  code: 'ERR_REQUIRE_ESM'
}

Is there any chance to make make-runnable packages can be run on ESModule?

Or is there another way to run a function from CLI with ESModule?

about 4 years ago · Juan Pablo Isaza
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