Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!