Instead of relative module imports I would like to import my modules like this: import { IntHelper } from 'utils/IntHelper';
. Even though intellisense works fine in VSCode the transpiled javascript files throw an exception: Cannot find module
.
My project structure:
root
- dist
- src
- MyProject.ts
- utils
- IntHelper.ts
- tsconfig.json
File: MyProject.ts
import { IntHelper } from 'utils/IntHelper';
File: IntHelper.ts
export module IntHelper {
export const xy: string = 'Test';
export function crossSum(int: number) {
return int; // Nonsense - ofcourse.
}
}
Tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"*",
"src/*"
]
}
}
}
My question:
Why does it throw the cannot find module exception in the javascript files even though it appears to be fine in the typescript files? When I hover the 'utils/IntHelper'
part in my import line in the typescript file VSCode would also show the correct path to that module.
webpack
,fusebox
, or are you directly usingtsc
? – Audacity--traceResolution
to typescript compiler in order to see why your module is not resolved. If it is resolved by the compiler, your problem might come from your building solution. – Audacityimport { IntHelper } from './utils/IntHelper';
– Kendalkendall