I have project in typescript. I am trying to debug with preLaunchTask to transpile typescript into js in folder build.
this is my tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "es2019", "esnext.asynciterable"],
"sourceMap": true,
"outDir": "./build",
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": false,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "src",
"paths": {
"*": ["./*"]
},
"types": ["node"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}
this is my launch.json
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug TypeScript in Node.js",
"preLaunchTask": "typescript",
"program": "${workspaceFolder}/api/src/index.ts",
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"outFiles": [
"${workspaceFolder}/api/build/**/*.js"
],
"sourceMaps": true
}
]
}
and this is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "api/tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": "build",
"label": "typescript"
}
]
}
I am getting
C:\Program Files\nodejs\node.exe .\api\build\index.js
Uncaught Error: Cannot find module 'database/createConnection
createConnection.js is located in build/database
Clearly I have something with paths, because __importDefault(require("database/createConnection")); this is line of code in index.js but not quite sure where to look at. Can you help me with this issue? I have found this similar topic cannot find typescript module . It seems that transpilling typescript didn't add base path to te imports.
EDIT: I have tried install module-alias and set in package.json
"_moduleAliases": {
"*": "./"
}
then I added this line on beginning of index.js
require('module-alias/register');
but it doesn't work... I am also experimenting with link-module-alias but can't make symlink * work. I need all paths with default prefix ./