I'm trying to compule the following typscript file
import { magic } from 'lib/magic';
magic();
The filestructure is:
./src/
main.ts
lib/
a/magic.ts
b/magic.ts
Inside tsconfig.json I map lib/magic
to the right file as follows
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"lib/*": [ "src/lib/a/*" ]
}
},
"include": [ "./src/**/*.ts" ],
"exclude": [ "./node_modules" ]
}
It is that paths
section that maps that import lib/magic
to ./src/lib/a/magic.ts
.
So, I can compile as follows
$> tsc -p ./tsconfig-a.json
It produces output in dist
. However, when I try to run it
$> node ./dist/main.js
internal/modules/cjs/loader.js:626
throw err;
^
Error: Cannot find module 'lib/magic'
Require stack:
...
It makes sense, because in dist there is no such thing as lib/magic
. Any suggestions how to fix this?