Home · Topic · 19 entries
TypeScript errors when Node runs your .ts files
Node now runs TypeScript files without a build step, which moved a whole class of errors from the compiler to the runtime: extensions Node refuses, syntax that cannot be stripped, and imports that only resolve for the type checker. Every entry below was reproduced on current Node and TypeScript, with the exact versions written at the top of the post.
Entries
- No.113
Fix: TS18046 'error' is of type 'unknown' in a catch block
Why TS18046 appeared after upgrading to TypeScript 6 or 7 with no config change, tested on 5.9.3 to 7.1 beta, and which fixes pass: instanceof, a helper, any.
> a.ts(1,53): error TS18046: 'error' is of type 'unknown'.
FIXED3 min - No.109
Better Auth: Invalid origin, default secret and base URL errors
Better Auth's Invalid origin, MISSING_OR_NULL_ORIGIN, default secret and base URL errors: 24 setups on 1.7.27 and the status, code and log line each one gave.
> 403 {"message":"Invalid origin","code":"INVALID_ORIGIN"}
FIXED4 min - No.092
TypeScript 7.1 beta tested: ts-jest, ESLint, NestJS, Angular
On TypeScript 7.1.0-beta, ts-jest, typescript-eslint, ts-node and TypeDoc failed exactly as on 7.0, and so did NestJS, Angular, vue-tsc, svelte-check and astro check. The beta does ship a compiler API, but at new entry points (typescript/sync and typescript/async) that no tool uses yet. The side-by-side setup with TypeScript 6 fixed every one I re-ran.
TESTED4 min - No.067
bun check vs tsc: TypeScript type-check speed, tested
On Zod, bun check took 3.7 s against 13.7 s for tsc 7 and 58 s for tsc 6, and printed the same 31 errors as tsc 7, line for line. On Hono, 7 referenced projects, it took 3.8 s against 7.3 s for tsc 7 -b, with nothing built first. The trap: in a project whose package.json has a "check" script, bun check runs that script and never type-checks.
TESTED4 min - No.053
Prisma P1012: "url is no longer supported in schema files"
Prisma 7 rejects the url line every older tutorial uses. Reproduced on 7.10.0, plus directUrl, the .env trap and the adapter error that comes next.
> Error: Prisma schema validation - (get-config wasm)
DATABASE3 min - No.051
Bun "error: Cannot find module": every cause, tested
Bun prints the same Cannot find module error for six different problems. Each one reproduced on Bun 1.4.2 on Windows and Linux, with the fix that worked.
> error: Cannot find module '@mono/ui' from 'D:\nk-repro\bun-cnf\e-mono\apps\web\index.ts'
FIXED9 minWindows - No.042
SvelteKit 3 migration, tested: what sv migrate misses
sv migrate sveltekit-3 upgraded every package and moved the config correctly, but left three removed options in place, so the first build failed three times in a row. Worse, it rewrote a working {base}/about link into one that 404s, and that passed both the build and svelte-check.
TESTED5 min - No.029
TypeScript 7 migration guide: breaking changes, tested
Every option TypeScript 6.0.3 marked as deprecated was a hard error on 7.0.2, and ignoreDeprecations no longer silences it. Two defaults that arrived in 6.0 (strict on, @types not loaded automatically) also break projects coming straight from 5.9.
TESTED7 min - No.028
Does NestJS, Next.js, Angular or Vue work with TypeScript 7?
Next.js 16.3.6 built and type-checked on plain TypeScript 7.0.2. Angular 22.2, Vue with vue-tsc 3.3 and NestJS 12 all failed, and all three built again on Microsoft's side-by-side setup, with tsc still on 7.0.2. Nuxt, Svelte and Astro still built on 7, but their type-check commands refused it until TypeScript 6 was installed alongside.
TESTED8 min - No.027
Angular compilation initialization failed on TypeScript 7
Angular 22 crashes on TypeScript 7 with reading 'Error', not the usual version warning. What actually failed, and the setup that builds with tsc 7, tested.
> Application bundle generation failed. [0.412 seconds]
FIXED3 min - No.023
Fix: TypeScript enum is not supported in strip-only mode
Node's ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX for enum, parameter properties, namespace, export = and import =. Two ways to run it unchanged, both tested.
> enum Color { Red, Green }
FIXED4 min - No.021
Fix: typescript-eslint does not support TS 7.0 (ESLint on TS 7)
When typescript-eslint will support TypeScript 7, why npm refuses the install, and the setup that keeps TypeScript 7 while ESLint runs normally today.
> npm error code ERESOLVE
FIXED4 min - No.019
TypeScript 7 with ts-jest, ESLint, ts-node: 9 tools tested
Plain TypeScript 7 broke ts-node, ts-jest, typescript-eslint, TypeDoc and ts-loader, and npm refused to install it at all without a flag. Microsoft's side-by-side setup ran all 9 tools with no errors while tsc stayed on 7.
TESTED9 min - No.015
Fix: Cannot read properties of undefined (reading 'fileExists')
ts-node or ts-loader crashing with "reading 'fileExists'" on TypeScript 7? Reproduced on Windows 11 and Ubuntu, before your code even runs: four ways out.
> C:\project\node_modules\ts-node\dist\configuration.js:91
FIXED5 min - No.014
TS1294: syntax not allowed with 'erasableSyntaxOnly', fixed
TS1294: TypeScript rejects your enum, namespace or constructor shorthand. Why new projects turn this on, what each piece becomes, and when to switch it off.
> src/a.ts(1,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
FIXED4 min - No.013
Fix: ERR_MODULE_NOT_FOUND Cannot find module in ES modules
Node can't find a file that is clearly there. What ES modules changed about relative imports, why TypeScript path aliases break at runtime, and what to change.
> node:internal/modules/esm/resolve:275
FIXED4 min - No.012
Unknown file extension ".ts" (ERR_UNKNOWN_FILE_EXTENSION)
Node refuses to run your TypeScript file. The version where this stops happening, what ts-node has to do with it, and the one-line way to run .ts today.
> node:internal/modules/esm/get_format:189
FIXED5 min - No.011
Bun vs Node.js 24 benchmark: startup, TypeScript and tests
Bun started 1.7× faster, ran a TypeScript file 3× faster and finished the same test suite 5× faster. The tight number-crunching loop was close: Node won it on Bun 1.4.2, and on 1.4.3 it was a toss-up. The HTTP test hit a limit of this machine, not of either runtime.
TESTED5 min - No.009
Fix: Vite “Failed to resolve import” for @/ path aliases
Vite can't resolve @/ imports: why the build can pass while the dev server and Vitest fail, and the configs that fix all three. Tested on Vite 8.3.5.
> [vite] Internal server error: Failed to resolve import "@/utils/hello"
FIXED4 min
Post card · Every Sunday
What broke this week.
One email on Sundays: the Node, TypeScript, Python and AI SDK releases that broke builds that week, each one reproduced, with a link to the fix that worked. Never shared, and you can leave any time.
— Nilay