Skip to content

Error when evaluating SSR module ./server.mjs: Cannot split a chunk that has already been edited (0:76 – "import.meta") #31978

Open

Description

@Maryannah

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

testing-app.zip

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

Activity

  1. DibyodyutiMondal commented on Dec 5, 2025

    @DibyodyutiMondal

    Same, I tried to use it with better-auth

  2. jakob0fischl commented on Dec 11, 2025

    @jakob0fischl

    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 start for 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 again

  3. parksmojo commented on Dec 11, 2025

    @parksmojo

    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.

  4. Maryannah commented on Dec 17, 2025

    @Maryannah
    Author

    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)

  5. added a commit that references this issue on Mar 2, 2026
  6. added a commit that references this issue on Mar 23, 2026
  7. Joyzyy commented on Jul 24, 2026

    @Joyzyy

    Hit the same thing on @angular/build 22.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.meta and an imported binding named meta. The SSR dep prebundle produces exactly that. Every chunk in deps_ssr/ starts with the esbuild banner

    import { createRequire } from 'module';const require = createRequire(import.meta.url);

    (that's the 0:76 in the error), and if the prebundled package exports a meta, the chunk also has import { ..., meta, ... } from "./chunk-XXXX.js". vite 7.3.5's isRefIdentifier doesn't skip MetaProperty, treats the meta in import.meta as a reference to the import, and ssrTransform edits the same range twice → magic-string throws.

    So any dependency exporting a symbol named meta triggers this. Mine was @orpc/contract@2.x (1.x didn't export meta, 2.x does).

    Repro: ng new repro --ssr, install any package whose entry contains export 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions