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

275
Visualizações
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 Respostas
Responde à pergunta

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 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