Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda