I am trying to generate JS code with the following tsconfig.json
{
"compilerOptions": {
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["ES2019","dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
/* Modules */
"module": "esnext", /* Specify what module code is generated. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
/* JavaScript Support */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
/* Emit */
"outDir": "./dist/", /* Specify an output folder for all emitted files. */
"noEmit": true, /* Disable emitting files from a compilation. */
/* Interop Constraints */
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src/**/*.ts", "src/Container.js"],
"exclude": ["node_modules/**/*", "dist/**/*","konva/*"],
}
This configuration generates one js file in the dist directory for each TS file, this way I can mantain the file structure.
The problem is that I need to import Konva lib from npm in order to use it, and when I compile I get this import in the JS files which need this lib:
import Konva from "konva"
This raises an error because it is not a valid path. Right now I have a python script removing this line from the resulting files, but I would like to remove it because it is an extra dependency just for removing one line.
When running the website it does not have any problem because I import Konva lib from CDN.
I am pretty new to TS and I don’t know if it is possible to remove the import statement from npm modules or if I have to bundle everything together, any tip is welcome.
Thanks.