ZettelKasten part 8
Simultaneous location and source mapping
This is a followup to a previous article, ZettelKasten Part 7
Source maps
Source Maps what are they good for? Finding out where the heck problems are. Since I'm writing in typescript I'm seeing all sorts of fun issues where I see an error and it tells me where it is. In the compiled JS. Which isn't useful since that's not the files I'm editing.
In tsconfig.json
:
{
"compilerOptions": {
"outDir": "dist",
"esModuleInterop": true,
"sourceMap": true
},
"exclude": ["node_modules", "tst"]
}
And I try it out by throwing an exception in the middle of my list API.
And it still sucks:
Error: Bad thing happened
at /home/user/projects/ZettelKasten/dist/index.js:96:23
at step (/home/user/projects/ZettelKasten/dist/index.js:33:23)
at Object.next (/home/user/projects/ZettelKasten/dist/index.js:14:53)
at fulfilled (/home/user/projects/ZettelKasten/dist/index.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
Hmmmm....
Stack Overflow says "do a bunch more stuff"
So:
yarn add source-map-support
And then in my package.json
:
"server": "npx tsc && node -r source-map-support/register dist/index.js",
"migrate": "npx tsc && yarn copyFiles && node -r source-map-support/register dist/migration.js",
Error: Bad thing happened
at /home/user/projects/ZettelKasten/src/index.ts:50:11
Perfect.
Moving on.
The adventure continues in ZettelKasten Part 9