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

155
Visualizações
Javascript VSCode function definition broken with module exports

I'm working on a Chrome extension and have a set of js files imported in the extension's popup in <script defer src="../utils/X.js"></script> tags.

The folder structure looks like

src/
  utils/
    parser.js
    functions.js
    other.js
  popup/
    popup.js
    popup.html

popup.js uses functions from files in utils/ and the files in utils/ use each other's functions.

All was going well and I could navigate to function definitions with cmd+click

As I integrated tests, and to be able to test my functions in a node environment (mocha) I added the following at the bottom of my util files:

if (typeof module !== "undefined" && module.exports != null) {
    module.exports = {
        log,
        ...
    };
}

And that breaks VSCode's ability to Go to Definition, not sure why or how to fix it.

For reference, here's my jsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
    },
    "include": [
        "src/**/*.js"
    ]
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem comes from VSCode's JS and TS language features relying on module.exports = {...} to determine whether a file should be treated as a script or a module. A workaround is therefore to trick it with the following:

if (typeof module !== "undefined" && module.exports != null) {
    var dummyModule = module;
    dummyModule.exports = {
        log,
        ...
    };
}
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