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

Open
#31,978 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
angular, typescript, vite

Research direction

Unpack testing-app.zip and inspect src/server.ts, especially line 20, then reproduce the failure with npx ng serve. Trace the SSR transformation shown in the Vite stack and compare behavior with that line enabled or commented; done means the minimal reproduction serves successfully with the intended server code intact.

Written by the indexing model from the issue text.

Description

angular/build:dev-server area: @angular/build needs: investigation
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

Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.