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

516
Visualizações
require('node-fetch') gives ERR_REQUIRE_ESM

I just use

const fetch = require('node-fetch')

And I get

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\rollbot\index.js not supported.
Instead change the require of C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js in C:\Users\Alex\Desktop\rollbot\index.js to a 
dynamic import() which is available in all CommonJS modules.
{
  code: 'ERR_REQUIRE_ESM'
}

All my other packages work, just node-fetch does this. What should I do in order to use node-fetch?

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

0

From the node-fetch package readme:

node-fetch is an ESM-only module - you are not able to import it with require. We recommend you stay on v2 which is built with CommonJS unless you use ESM yourself. We will continue to publish critical bug fixes for it.

If you want to require it, then downgrade to v2.

The other option you have is to use async import('node-fetch').then(...)

over 4 years ago · Santiago Trujillo Relatório

0

In my case, I personally found it easier to require ('cross-fetch') instead. The documentation is here: cross-fetch

It can be used in CommonJS as well as ES6 modules.

over 4 years ago · Santiago Trujillo Relatório

0

What I finded is that the latest version of node-fetch changed to ES modules by default. You can do:

  1. Uninstall the current version of node-fetch with npm uninstall node-fetch
  2. Install the second version: npm install node-fetch@2

It has worked for me!

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