dev: import-protection plugin reads `ModuleInfo.code`, which Vite does not support β throws and breaks the client entry #8554
Summary#
In dev, the import-protection plugin's resolveExportsForDeniedSpecifier falls back to reading ModuleInfo.code. That property is not supported by Vite, and reading it throws rather than returning undefined, so the fallback turns a recoverable situation into a 500 that takes down the client entry. Pages render from SSR but never hydrate, so every interactive element is inert.
This is not a Vite 8 regression β it reproduces on the Vite 7 line too.
Versions#
| package | version |
|---|---|
@tanstack/react-start | 1.168.59 (latest) |
@tanstack/start-plugin-core | 1.171.48 (latest) |
@tanstack/react-router | 1.170.40 |
vite | 8.3.1 β also 7.3.6 |
| Node | 26.9.0, Linux x86_64 |
Where#
packages/start-plugin-core/src/vite/import-protection-plugin/plugin.ts, in resolveExportsForDeniedSpecifier (line 381 in the published dist/esm):
const importerCode = env.transformResultProvider.getTransformResult(importerFile)?.code
?? (importerIdHint && ctx.getModuleInfo
? ctx.getModuleInfo(importerIdHint)?.code ?? undefined
: undefined)
The optional chain does not help. The failure is on property access, not on a nullish value. Vite returns a Proxy from getModuleInfo whose get trap throws for anything other than id and meta:
if (!module.info) module.info = new Proxy({ id, meta: module.meta || EMPTY_OBJECT$1 }, {
get(info, key) {
if (key in info) return info[key]
if (key === 'then') return
throw Error(`[vite] The "${key}" property of ModuleInfo is not supported.`)
}
})
Confirmed present in both vite@8.3.1 (dist/node/chunks/node.js) and vite@7.3.6 (dist/node/chunks/config.js), so downgrading Vite does not avoid it.
Reproduction (no browser, no HTTP request)#
Boot a dev server in middlewareMode, render nothing, and ask the client environment to transform a server-function module. That transform is what walks the import graph and reaches the fallback. Shaped after #8447's own repro.
import { createServer } from 'vite'
const server = await createServer({
server: { middlewareMode: true, hmr: false },
logLevel: 'silent',
})
const client = server.environments.client
for (const id of [
'/src/server/auth/functions.ts',
'/src/server/checkout/functions.ts',
'/src/server/db/functions.ts',
]) {
try {
await client.transformRequest(id)
console.log('OK ', id)
} catch (error) {
console.log('THREW', id, '::', error.message)
}
}
await server.close()
Actual output:
OK /src/server/auth/functions.ts
THREW /src/server/checkout/functions.ts :: [vite] The "code" property of ModuleInfo is not supported.
OK /src/server/db/functions.ts
Browser symptom#
[vite] (client) Pre-transform error: [vite] The "code" property of ModuleInfo is not supported.
Plugin: tanstack-start-core::server-fn:client
File: /β¦/src/server/auth/functions.ts
then in the page:
Uncaught TypeError: Failed to fetch dynamically imported module:
http://localhost:3000/node_modules/@tanstack/react-start/dist/plugin/default-entry/client.tsx
SSR is unaffected β every route returns 200 β but hydration never completes. Controls render their pre-hydration state indefinitely (an add-to-cart button stuck on "Loading cartβ¦"), and clicks do nothing.
Stack#
resolveExportsForDeniedSpecifier (import-protection-plugin/plugin.js:381)
handleViolation (import-protection-plugin/plugin.js:712)
reportOrDeferViolation (import-protection-plugin/plugin.js:734)
ResolveIdContext.handler (import-protection-plugin/plugin.js:959)
StartCompiler.resolveImportKind (start-compiler/compiler.js:876)
StartCompiler.resolveIdentifierKind (start-compiler/compiler.js:785)
Observations#
- It is order-dependent, not content-dependent. In one dev session, transforming a light
functions.tsfirst made both heavy ones pass; transforming one heavy one first made the second one fail. That points at thetransformResultProvidercache missing for the second module rather than at anything in the file's imports. - It is not specific to heavy imports. A
functions.tsimporting a single server-only module transforms fine, and the same file can both pass and fail depending on what was transformed before it. - The plugin's own violation-suggestion string tells users to "move the server-only import out of this file into a separate
.server.tsmodule". Because the failure is order-dependent rather than content-dependent, that is unlikely to be a fix, but I did not rule it out exhaustively. - Nothing in the app's own code is required to trigger it. I reproduced it with a
functions.tsthat only callscreateServerFnand imports one server-only module, once another module had been transformed first.
Suggested fix#
Guard the property access, or use a capability check. Something in the shape of:
const info = ctx.getModuleInfo?.(importerIdHint)
const fallbackCode = typeof info?.code === 'string' ? info.code : undefined
typeof on the access still throws, so the access itself needs to be guarded β e.g. a try/catch around the read, or dropping the fallback entirely and treating a missing transform result as "no mock exports" (resolveExportsForDeniedSpecifier already returns [] on that path).
Related#
#8447 is a different failure in the same dev area (server-fn id validator recovery), same package family. This one is the import-protection path.
please provide a complete minimal start project that reproduces this issue instead of those synthetic setups.
Root cause found, and the app-side fix#
This is not purely an upstream problem. The trigger is a heavy
functions.tsboundary module β one that imports server-only modules directly alongside itscreateServerFndeclarations. Moving that logic into a*.server.tsmodule and leaving the boundary as validation plus declarations fixes it completely, with no config change and no error suppression.Controlled for position, because position was a red herring. In one dev session:
OK db/functions.ts (trivial: 1 import, 1-line handler) OK auth/functions.ts (substantial) THREW checkout/functions.ts (substantial) OK checkout/probe-thin.ts (thin, placed LAST, after a throw)The thin module survives in last position, so the differentiator is the weight of the boundary module, not where it appears in the transform order.
After moving the implementation of
authandcheckoutintoservice.server.tsfiles, all seven boundary modules transform with zero errors, every route loads with no error overlay, client-side navigation works, and a server function call completes.auth/functions.tswent 308 β 92 lines andcheckout/functions.ts~140 β 71.So for anyone hitting this: splitting the boundary module is a real workaround today, and it is probably the better shape regardless. But the underlying fault is still yours β the fallback should not be able to throw, and a module that obeys the documented pattern should not need a workaround to compile.
Updated comment above about ordering: with a thin first module the heavy ones pass, which I initially read as "order-dependent, not content-dependent". That was wrong β it is content-dependent, and the thin module just does not enter the pathology.
For reference, the skill guidance in
tanstack-start-best-practices(file-separation) prescribes exactly this layout β.server.tsfor server-only logic,.functions.tsfor the boundary. It is worth making the plugin tolerate the heavier shape too, since both are legitimate.
Sign in to join this conversation.
Correction and sharper repro after further testing#
One claim in my original report was too loose.
checkout/functions.tsis not inherently the failing module β that was an artefact of the order I happened to use. Here is the deterministic picture, each line a separate dev session:checkoutaloneauthalonedbβcheckoutdbβauthcheckoutβauthauthβcheckoutdbβauthβcheckoutSo the rule is not "the second module throws" and not "this file is bad". It is:
Once one substantial
functions.tshas been transformed, the next substantial one throws β unless a trivial one went first.db/functions.tsis the trivial one: a singlecreateServerFnwith one import and a one-line handler. Transformed first, it leaves the plugin in a state where both heavy modules then pass. That is the strongest evidence that this is a cache priming problem rather than anything about a file's imports, and it also makes the bug much easier to hit in a real app, where the root layout and the first route both pull in server functions.A minimal, deterministic repro that shows the failure and the avoidance:
Happy to narrow further if it would help β in particular, whether priming something in
env.transformResultProviderbefore the first heavy transform is enough to avoid it entirely, which would point at the fix.