I have the following Node.js with Typescript project that runs absolutely fine. However, during debugging session, I noticed that exported constant from another Typescript file are always undefined
:
I kinda suspect that this is due to the empty names
array in the generated source maps:
{
"version": 3,
"file": "main.js",
"sourceRoot": "",
"sources": [
"../src/main.ts"
],
"names": [], // <---- empty
"mappings": ...details omitted...
}
Is there a way to generate proper source map from a Typescript compiler or maybe other solution to solve this debugging issue? Below are my tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"sourceMap": true,
"allowJs": true,
"outDir": "dist",
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node"
],
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
I'm using Typescript 3.7.5.
The project was simply run through Webstorm's Node runner:
Side note: This issue didn't happen when I debug an Angular application that is run through ng serve
. Not sure what ng serve
do differently from standard tsc
.
Yes, the empty "names": []
in sourcemaps is the issue - tsc
compiles your named import to category_1.ANIMAL_TYPE
, and there are no name mappings, so the variable is undefined in debugger... You will face the same issue when debugging in VSCode, for example:
You can inspect the category_1
object to see the values:
I'm not aware of any way to alter tsc
behavior:(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With