Repository navigation
Error when evaluating SSR module ./server.mjs: Cannot split a chunk that has already been edited (0:76 – "import.meta") #31978
Copy link
Copy link
Open
Labels
angular/build:dev-serverarea: @angular/buildneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is needed
Description
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
I just created an Angular application and
- Added Hono and configured it for SSR
- Added Drizzle ORM
- Added Better Auth
I configured every library following their documentation, but when I run npx ng serve I get this error :
6:31:46 PM [vite] (ssr) Error when evaluating SSR module ./server.mjs: Cannot split a chunk that has already been edited (0:76 – "import.meta")
at MagicString._splitChunk (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3823:10)
at MagicString._split (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3814:43)
at MagicString.update (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3638:8)
at onIdentifier (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16139:77)
at file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16251:37
at Array.forEach (<anonymous>)
at walk$1 (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16250:14)
at ssrTransformScript (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16116:2)
at async loadAndTransform (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:23318:64)
at async fetchModule (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:34612:15)
Commenting line 20 of src/server.ts, then re-running the serve command makes it work.
Minimal Reproduction
Exception or Error
6:31:46 PM [vite] (ssr) Error when evaluating SSR module ./server.mjs: Cannot split a chunk that has already been edited (0:76 – "import.meta")
at MagicString._splitChunk (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3823:10)
at MagicString._split (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3814:43)
at MagicString.update (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:3638:8)
at onIdentifier (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16139:77)
at file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16251:37
at Array.forEach (<anonymous>)
at walk$1 (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16250:14)
at ssrTransformScript (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:16116:2)
at async loadAndTransform (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:23318:64)
at async fetchModule (file:///home/max/projects/migal/mi-points/node_modules/vite/dist/node/chunks/config.js:34612:15)
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 21.0.1
Angular : 21.0.1
Node.js : 22.18.0
Package Manager : npm 11.6.1
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.0.1 │ ^21.0.1 │
│ @angular/cli │ 21.0.1 │ ^21.0.1 │
│ @angular/common │ 21.0.1 │ ^21.0.0 │
│ @angular/compiler │ 21.0.1 │ ^21.0.0 │
│ @angular/compiler-cli │ 21.0.1 │ ^21.0.0 │
│ @angular/core │ 21.0.1 │ ^21.0.0 │
│ @angular/forms │ 21.0.1 │ ^21.0.0 │
│ @angular/platform-browser │ 21.0.1 │ ^21.0.0 │
│ @angular/platform-server │ 21.0.1 │ ^21.0.0 │
│ @angular/router │ 21.0.1 │ ^21.0.0 │
│ @angular/ssr │ 21.0.1 │ ^21.0.1 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 5.9.3 │ ~5.9.2 │
│ vitest │ 4.0.14 │ ^4.0.8 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
angular/build:dev-serverarea: @angular/buildneeds: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is needed
Activity
DibyodyutiMondal commentedon Dec 5, 2025
Same, I tried to use it with better-auth
jakob0fischl commentedon Dec 11, 2025
I had this issue as well and was able to resolve it by downgrading zod from 4.1.13 to 4.1.12
Also tried it in a fresh project with just zod and had no issues there, I think this might have something to do with some specific zod feature that is being used in better-auth.
You might want to use something like
pnpm i && rm -rf .angular && pnpm --package=@angular/cli@latest dlx ng cache clean && pnpm run startfor testing to ensure there are no caches. When I was testing this once it ran successfully it tended to keep working even with the zod version updated againparksmojo commentedon Dec 11, 2025
I had the same issue, but my application doesn't use better-auth. Downgrading zod to 4.1.12 did fix the issue thankfully, but removing the cache didn't help with running 4.1.13.
Maryannah commentedon Dec 17, 2025
Issue is indeed with Zod version, thank you @jakob0fischl & @parksmojo !
(Don't know if this should stay open, feel free to close or resolve as needed for me)
[#87] Externalize zod from SSR bundle to fix Vite dev server
[#87] Externalize zod from SSR bundle to fix Vite dev server
Joyzyy commentedon Jul 24, 2026
Hit the same thing on
@angular/build22.0.7 after a dependency upgrade. Root cause is a vite bug in ssrTransform, already fixed in vite 8.0.3 (vitejs/vite#22019); angular still bundles 7.3.5.The bug needs two things in the same module: an
import.metaand an imported binding namedmeta. The SSR dep prebundle produces exactly that. Every chunk indeps_ssr/starts with the esbuild banner(that's the
0:76in the error), and if the prebundled package exports ameta, the chunk also hasimport { ..., meta, ... } from "./chunk-XXXX.js". vite 7.3.5'sisRefIdentifierdoesn't skipMetaProperty, treats themetainimport.metaas a reference to the import, and ssrTransform edits the same range twice → magic-string throws.So any dependency exporting a symbol named
metatriggers this. Mine was@orpc/contract@2.x(1.x didn't exportmeta, 2.x does).Repro:
ng new repro --ssr, install any package whose entry containsexport const meta = {};, import it anywhere in the server graph,ng serve→ 500 on every request.Workaround until the vite dep gets bumped (pnpm patch):
// dist/node/chunks/config.js function isRefIdentifier(id, parent, parentStack) { + if (parent.type === "MetaProperty") return false; if (parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id) return false;Edit: seems to be fixed in the next version (21.1.0) by commit b9681c0