Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

255
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda