How to debug?

Hi,

I am building a rag app based on this tutorial:

App seems to work but I dont manage to setup the debugger:

E.g. I have the file embedding.ts

import { embed, embedMany } from ‘ai’;
import { openai } from ‘@ai-sdk/openai’;
import { db } from ‘../db’;
import { cosineDistance, desc, gt, sql } from ‘drizzle-orm’;
import { embeddings } from ‘../db/schema/embeddings’;

const embeddingModel = openai.embedding(‘text-embedding-ada-002’);

const generateChunks = (input: string): string => {
return input
.trim()
.split(‘.’)
.filter(i => i !== ‘’);
};

generateChunks(‘This is a test. This is another test. This is a third test. This is a fourth test. This is a fifth test.’);

I set the breakpoint in the last line.

I am using VSCode and tried to use follow launch config:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debug code with Visual Studio Code
“version”: “0.2.0”,
“configurations”: [
{
“type”: “node”,
“request”: “launch”,
“name”: “embedding_debug”,
“skipFiles”: [
“<node_internals>/"
],
“program”: “${workspaceFolder}/code/lib/ai/embedding.ts”,
“outFiles”: [
"${workspaceFolder}/
/*.js”
]
}
]
}

However it always throws me an error:

/usr/local/bin/node ./code/lib/ai/embedding.ts
Process exited with code 1
Uncaught TypeError TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” for /Users/kosmirnov/Desktop/chatmottest/code/lib/ai/embedding.ts
at getFileProtocolModuleFormat (<node_internals>/internal/modules/esm/get_format:219:9)
at defaultGetFormat (<node_internals>/internal/modules/esm/get_format:245:36)
at defaultLoad (<node_internals>/internal/modules/esm/load:120:22)
— await —
at runEntryPointWithESMLoader (<node_internals>/internal/modules/run_main:138:19)
at loadESMFromCJS (<node_internals>/internal/modules/cjs/loader:1329:42)
at (<node_internals>/internal/modules/cjs/loader:1536:5)
at (<node_internals>/internal/modules/cjs/loader:1706:10)
at (<node_internals>/internal/modules/cjs/loader:1289:32)
at (<node_internals>/internal/modules/cjs/loader:1108:12)
at traceSync (<node_internals>/diagnostics_channel:322:14)
at wrapModuleLoad (<node_internals>/internal/modules/cjs/loader:220:24)
at executeUserEntryPoint (<node_internals>/internal/modules/run_main:170:5)
at (<node_internals>/internal/main/run_main_module:36:49)

I am new to TypeScript and I have Python background. I come from a world where you press the debug button and it debugs :slight_smile:

Would appreciate if someone could help.

Hey @kosmirnov-gmailcom

this looks like also new territory for me :smiley: so lets learn together!

It looks like you are using a VSCode debugger, and it looks like you are trying to start a typescript file which node isn’t able to launch.

depending on your node version, you may be able to add --experimental-strip-types OR if you are on node 23, that should support TS by default.

It looks like just an error with node executing the ts file. Are you able to run node /path/to/embeddings.ts?

The weird thing is that I can execute the file with following command in my terminal:

npx tsx ./lib/ai/embedding.ts
[
‘This is a test’,
’ This is another test’,
’ This is a third test’,
’ This is a fourth test’,
’ This is a fifth test’
]

How else would you debug this sort of things ? I am wondering …?

Yup, so tsx is different than using node to execute typescript files. that is why it is working there but not in the debugger (which is using node the command)