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

246
Visualizações
How to use 'require' for node-fetch in a function

I am trying to follow this tutorial.

I am stuck at 1:04.

Ania is able to start the netlify dev and return results from her database.

I get an error with the function. I can see in Ania's github repo, that she uses the code that generates the error for me. I wish I could begin to understand why she doesn't get the same error from the same code.

The function Ania wrote uses a require statement as follows:

const fetch = require('node-fetch');

When I use this line, I get an error that says:

Error - require() of ES Module /Users/melaniemaslem/AniaKubowTutorials/netflix-datastax-clone/node_modules/node-fetch/src/index.js from /Users/AniaKubowTutorials/netflix-datastax-clone/functions/getGenres.js not supported. Instead change the require of index.js in /Users/AniaKubowTutorials/netflix-datastax-clone/functions/getGenres.js to a dynamic import() which is available in all CommonJS modules.

I tried replacing the require statement with

const fetch = import('node-fetch');

When I try that, I get an error that says:

TypeError - fetch is not a function

I have seen this post, which suggests I could replace that line with:

import fetch from 'node-fetch';

When I try that, I get an error that says:

SyntaxError - Cannot use import statement outside a module

That same SO post has an answer with a fall back suggestion of using something out of date. It links to this page for advice. I don't know what to make of this or how to apply it to Ania's tutorial.

Can anyone see a way to use require in a function?

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