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

244
Visualizações
Why does `var exports = module.exports = {};` works but not `let exports = module.exports = {};`?

During code optimisation of my project, I was replacing all instances of var keyword with let because I think there is no particular use left for var. I did a 'Find & Replace' in all files to do this.

In some custom modules I had used statements like:

var exports = module.exports = {};

which worked fine.

Now, after replacing it with let, it became:

let exports = module.exports = {};

It does not work now and gives an error

SyntaxError: Identifier 'exports' has already been declared

Though I can use var and avoid this problem, I still want to know what is the reason behind this.

EDIT: I have not used let exports = <something>; anywhere in same module file. So this is the only statement where I have declared exports variable.

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

0

The reason is because exports is already initialized in Nodejs module system.

https://nodejs.org/api/modules.html#modules_module_exports

The object exists, module.exports when the module loads. Since let is scope specific it is preventing you from limiting the scope. const would also fail.

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