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

161
Views
how to prevent typescript from adding imports in compiled files

I'm building an electron js app with some js libraries like prismjs.

I tried adding @types/prismjs to my node modules and many other ways

but still typescript tries to import it import {something} from "prismjs" (in generated js file which I don't want it)

I have seen similar questions in stack overflow but none of them solved my issue.

app/ts config

{
    "compilerOptions": {
        "module": "ES2020",
        "target": "ES2021",
        "noImplicitAny": true,
        "removeComments": true,
        "allowUnreachableCode": false,
        "strictNullChecks": true,
        "strict": true,
        "noImplicitUseStrict": false,
        "alwaysStrict": true,
        "allowSyntheticDefaultImports": true,
        "typeRoots": ["../node_modules/@types"],
        "sourceMap": true
    }
}

app/script.ts

import { highlightElement } from "prismjs";

window.addEventListener("keyup", ev => {
    if (ev.key === "F5") window.location.reload();
});

const el = document.querySelectorAll("code")[1];
el.onkeyup = () => {
    highlightElement(el);
};

project structure enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

However... After hours of researching I finally found a way to solve this question. thanks to this answer https://stackoverflow.com/a/55377372/16906284

adding the two lines below in tsconfig.json would solve that problem...

{
    ...
    "typeRoots": [ "node_modules/types" ],
    "types": [ "prismjs" ]
}
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!