When deploying the project to Vercel, the build step using tsc && vite build is highlighted in red.
The runtime logs show a TypeError indicating an unknown file extension .ts for the database.ts module imported within api/index.ts
The TypeScript files should compile to JavaScript during the build process.
vercel.json
{ "version": 2, "buildCommand": "bun run build", "functions": { "api/index.ts": { "includeFiles": "src/**/*" } }, "rewrites": [ { "source": "/api/(.*)", "destination": "/api/index" }, { "source": "/(.*)", "destination": "/index.html" } ]}tsconfig.json
{ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "module": "ESNext", "lib": [ "ES2020", "DOM", "DOM.Iterable" ], "skipLibCheck": true, /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "isolatedModules": true, "moduleDetection": "force", "noEmit": true, /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "noUncheckedSideEffectImports": true }, "include": [ "src" ]}I think I know what the issue is but can't seem to solve it. I need to compile my ts files into js files so Node can execute them. I've tried the following:
Within vercel.json I've changed my buildCommand from the above to:
`"buildCommand": "bunx tsc && bunx vite build"`and commented out the the following lines within tsconfig.json,
// "allowImportingTsExtensions": true, // "noEmit": true,the above changes, eliminate the tsc && vite build being highlighted in red, during the build step, but I get the error:
Cannot find module '/var/task/src/server/database' imported from /var/task/api/index.jsThe error shows that api/index.ts got compiled to api/index.js by Vercel but it seems like the other files are not being compiled from ts to js or my vercel.json config is incorrect.
I've come across this issue https://github.com/TypeStrong/ts-node/issues/1062 and within it there are a few suggestions, such as this one by Rush, node --experimental-specifier-resolution=node --loader ts-node/esm file.ts
However, I didn't want to install ts-node since Vercel supports Bun with no config, so I figured package tsc should work.
Thank you in advance for any help.
