TypeScript & Frontend
20 lessons from merged PRs in TypeScript, Vite and Prisma, summarized in our own words. Real framework gotchas for your AI coding agent.
brain_seed_starter(instance_id="<your-brain-id>", stack="typescript")20 fixes from merged PRs
Every lesson below is a short summary in our own words and links to its upstream GitHub pull request in a permissive-licensed repository. Seed them into your Brain so your coding agent can find them when a similar problem comes up.
- Symptom
Vite build with an empty CSS or SCSS file as a rollup entry emits an empty JS file and a manifest entry pointing to it instead of a CSS asset.
Cause and fixCause: The CSS plugin guarded asset emission with a truthiness check on the chunk's CSS string, so an empty string skipped the CSS pipeline and the chunk was treated as plain JS. Fix: In plugins/css.ts the chunkCSS initialization and check were changed to tell apart 'no CSS processed' from 'processed but empty', so CSS entries always go through CSS emission.
- Symptom
An esbuild plugin in optimizeDeps.esbuildOptions.plugins throws when its build.onEnd callback reads result.metafile under Vite's Rolldown compatibility layer.
Cause and fixCause: convertEsbuildPluginToRolldownPlugin handed onEnd callbacks a proxy object that raised an error on any property access instead of a normal BuildResult. Fix: The converter now passes a minimal valid esbuild BuildResult with empty errors and warnings arrays and the other optional fields undefined, so checks like a missing metafile behave as in esbuild.
- Symptom
Setting build.target to esnext still lowers CSS during minification with Lightning CSS, and a :open rule disappeared from the minified output.
Cause and fixCause: convertTargets returned an empty object when all targets were esnext, and Lightning CSS interprets targets: {} as no browser supporting anything, unlike undefined which means no constraints. Fix: convertTargets now returns undefined rather than an empty object when every entry is esnext or cssTarget is false, and a unit test covers it.
- Symptom
When vite build or another CLI command fails with an AggregateError, the console shows only the top-level message and stack, hiding the individual errors inside it.
Cause and fixCause: The CLI error handlers in cli.ts logged e.stack, which does not include the nested errors of an AggregateError and is undefined for non-Error throws. Fix: All four catch blocks in cli.ts (dev server, build, optimize deps, preview) now log util.inspect(e), which prints nested errors and tolerates non-Error values.
- Symptom
Using import.meta.glob with a custom JSX import source makes the dependency scan fail, trying to resolve react/jsx-runtime despite the configured JSX settings.
Cause and fixCause: doTransformGlobImport in the optimizer scanner called transformSync without the user's configured OXC transform options, so custom JSX settings were ignored. Fix: The scanner's glob-import transform now passes the user-configured OXC transform options into transformSync.
- Symptom
With build.chunkImportMap enabled, a CSS-only change leaves the parent JS chunk's filename the same while its cached preload list now references a different CSS file.
Cause and fixCause: Dynamic JS dependencies used stable import-map specifiers, but extracted CSS dependencies were still referenced by content-hashed filenames. Fix: Each emitted CSS asset is now tracked back to its chunk, a stable CSS entry is added to the generated import map, and preload rewriting uses that specifier; builds without chunkImportMap are unchanged.
- Symptom
SSR builds with ssr.target set to webworker emit createRequire(import.meta.url) via Rolldown, which crashes on Cloudflare Workers where import.meta.url is undefined.
Cause and fixCause: resolveBuildEnvironmentOptions defaulted rolldownOptions.platform to node for every server build, ignoring the webworker target. Fix: The already computed isSsrTargetWebworkerEnvironment flag is now used so webworker SSR builds default the platform to browser instead of node.
- Symptom
TypeScript rejects in/out variance modifiers on a type alias whose body points at a generic interface, although the same modifiers work when the alias points at an object type.
Cause and fixCause: The checker's list of permitted object kinds for variance modifiers lacked reference types, which is how generic interfaces are represented. Fix: Added ObjectFlags.Reference to the permitted flags in checker.ts and added tests confirming nested references to object or primitive shapes still error only in the right cases.
- Symptom
Nested generic function calls in TypeScript inference leak an unbound type parameter from the outer signature into the inferred result type.
Cause and fixCause: Outer type parameters are projected onto inner expression types, but argument expressions were instantiated with the signature mapper, which over-eagerly instantiated inner calls, rather than the inference context. Fix: The checker now instantiates argument expression types with the inference context's mapper to complete the projected types, with new tests showing the inner-call case.
- Symptom
TypeScript 5.4 reports error 2590, a union type too complex to represent, when narrowing with large interfaces that worked on 5.3.
Cause and fixCause: Intersecting many union constituents built a huge cartesian product of members even though most combinations collapse to never. Fix: Intersections with four or more constituents that include unions are now split into two groups, so A & B & C & D is computed as (A & B) & (C & D), creating a few extra temporary types.
- Symptom
tsc --watch stops detecting file changes on macOS 14.4 when watching via directory-level fsevents, printing 'found 0 errors' without recompiling.
Cause and fixCause: The fs.watch event handler filtered events by timestamp even for directories, but a directory can emit change events for many reasons, so valid events were dropped. Fix: In sys.ts the timestamp-based filtering is no longer applied to directory watchers, and the virtual file system test helper was corrected to send realistic timestamps and events.
- Symptom
Setting isolatedModules: true explicitly alongside verbatimModuleSyntax: true triggers a compiler error, which breaks tools like Next.js that force isolatedModules on.
Cause and fixCause: The compiler in program.ts rejected an explicit isolatedModules value whenever verbatimModuleSyntax was enabled, even though the latter already implies it. Fix: The check in program.ts that errored on the combination was removed, and the related baseline error files were updated.
- Symptom
The TypeScript compiler crashes with RangeError: Map maximum size exceeded while checking projects using large type libraries such as antd or fontawesome types.
Cause and fixCause: Computing a relation between huge unions added so many entries to the relation cache that the underlying JavaScript Map hit Node's limit of about 16 million entries. Fix: The checker now reports an excessive-complexity error when computing one relation adds more cache entries than one eighth of the cache's current capacity, instead of crashing.
- Symptom
Organize Imports merges two imports from the same module into one statement even though they have different import attributes (with/assert clauses).
Cause and fixCause: The coalescing logic in organizeImports compared only module specifiers and ignored import attributes. Fix: Imports are now merged only if their import attributes also match; statements with the same specifier but different attributes are kept apart without being reordered.
- Symptom
Prisma's env() helper gives TS2344 when its generic argument is an interface rather than a type alias.
Cause and fixCause: The generic constraint Record<string, string | undefined> demands an index signature, which interfaces do not have. Fix: The env signature was simplified and a new EnvKey helper type restricts keys to string-or-undefined values, so both interfaces and type aliases type-check; a type-level test covers both and runtime is untouched.
- Symptom
Prisma Client infers the wrong result type when omit and include are combined inside a nested include, even though the returned data is correct.
Cause and fixCause: With nested select or include, TypeScript loses track of the keys of the argument type and discards the omit key during inference. Fix: In Result.ts the omit key is re-attached at that point with an A & { omit: A['omit'] } intersection, and a functional test for the nested case was added.
- Symptom
Installing Prisma packages on Node 25 fails when strict engine checks are enabled, although newer Node versions are not known to be broken.
Cause and fixCause: The engines field in the root, cli and client package.json files capped the allowed Node versions, blocking anything above the listed range. Fix: The Node version constraints in the three package.json files were loosened so higher Node releases are no longer rejected by engine checks.
- Symptom
Using Prisma.skip in a query with a $allModels.$allOperations query extension throws a runtime validation error, so strictUndefinedChecks does not work with extensions.
Cause and fixCause: deepCloneArgs treated the Skip instance as a plain object and cloned it into {}, which later failed the instanceof Skip check in serializeJsonQuery. Fix: deepCloneValue now returns early for Skip instances via isSkip(x), as it already does for ObjectEnumValue and FieldRef, with unit tests for top-level, nested and array cases.
- Symptom
Reading or writing Bytes fields through @prisma/adapter-pg fails under Vitest or Jest with the jsdom environment.
Cause and fixCause: jsdom runs in a separate JavaScript realm, so a Uint8Array created there fails instanceof Uint8Array checks performed in Node's realm. Fix: A cross-realm isUint8Array() helper in utils.ts, based on Object.prototype.toString, replaced the instanceof Uint8Array checks in client-engine-runtime files such as data-mapper.ts.
- Symptom
When a driver adapter throws an error Prisma does not recognise, the resulting message reads [object Object], leaving no hint which error kind occurred.
Cause and fixCause: The assertNever call in getErrorCode and renderErrorMessage interpolated err.cause, a plain object, into a template literal, which coerces it to [object Object]. Fix: The interpolation was replaced with the existing safeJsonStringify utility, which also handles BigInt and Uint8Array values, so the unknown cause is printed in readable form.