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

280
Vistas
Problem exporting module in node: functions not exported correctly

I have a module that has an index.js file and 2 different utility files with functions.

Index has:

const utl = require('./tools');
const updt = require('./update');

While both files have a version of (this is the update.js exports):

module.exports = { 
    updateResults, 
    addTeamIDsToArray, 
    updateTeamStats,
    retrieveRankings, 
    numbOfWeeksToToday }

And the tools.js exports:

   module.exports = {
    add_weeks,
    format_date,
    waitForMe, 
    chooseWinner
    }

However, when I check both constants in my index.js file, one of them is empty:

    console.log(updt)
    console.log(utl)

OUTPUT:

    {}
    {
      add_weeks: [Function: add_weeks],
      format_date: [Function: format_date],
      waitForMe: [Function: waitForMe],
      chooseWinner: [Function: chooseWinner]
    }

Why is my update file not exporting correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm assuming you mean both files have the same module.exports ?

It's impossible to answer this question without seeing whats in the "tools" directory, as it seems to be behaving correctly; returing an object of the contents exported from the file- in this case, an empty object. (Reason: OP added details)

If it's any consolation, I think you're doing this correct overall. This leads me to wonder a few things!

  • Have you tried changing the file name?
  • Using different import methods? (ESM import x from "x" / await import("x"))
  • Create some object random object (we'll call it obj = { updateResults, addTeamIDsToArray, ...}), add all the exported items, then module.exports = obj?
  • Destructuring the import to further debug? Ex: const { updateResults } = reqiure("./tools") ?
  • Obvious but made sure the relative path "./tools" is correct?

These are just a few things to check or try out, just to check.

And last but not least, good ole' turn it off and back on again just to be sure we cover it all.

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