Skip to content

[wrangler] fix: Angular auto-config treats non-SSR projects as assets-only SPA deployments#13039

Merged
petebacondarwin merged 4 commits intomainfrom
fix/angular-autoconfig-spa
Mar 24, 2026
Merged

[wrangler] fix: Angular auto-config treats non-SSR projects as assets-only SPA deployments#13039
petebacondarwin merged 4 commits intomainfrom
fix/angular-autoconfig-spa

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Mar 24, 2026

Fixes #12950.

When wrangler deploy (or wrangler setup) is run against a plain Angular SPA — created with ng new without the --ssr flag — the auto-config code was unconditionally trying to set architect.build.options.ssr.experimentalPlatform = "neutral" in angular.json. Since ssr doesn't exist in a non-SSR project's angular.json, this threw:

✘ [ERROR] Cannot set properties of undefined (setting 'experimentalPlatform')

Changes

packages/wrangler/src/autoconfig/frameworks/angular.ts

  • Added hasSsr() helper that checks whether architect.build.options.ssr exists and is truthy in angular.json
  • configure() now reads angular.json upfront and branches on SSR detection:
    • Non-SSR / SPA: Sets configurationDescription = "Configuring Angular SPA project (assets only)", returns an assets-only wranglerConfig (no main entry), and skips updateAngularJson, overrideServerFile, and installAdditionalDependencies
    • SSR: Sets configurationDescription = "Configuring project for Angular" and keeps all existing behaviour unchanged
  • Updated AngularJson type to make ssr optional (ssr?: Record<string, unknown> | false | null)
  • updateAngularJson now receives the already-parsed angularJson as a parameter to avoid reading the file twice

packages/wrangler/src/__tests__/autoconfig/frameworks/angular.test.ts (new)

14 unit tests covering:

  • Non-SSR project (no ssr field): assets-only config returned, no side effects triggered
  • ssr: false project: treated the same as non-SSR
  • SSR project: full SSR config generated, angular.json updated, src/server.ts created, xhr2 installed; dryRun skips all side effects

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this is a bug fix restoring expected behaviour

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@petebacondarwin petebacondarwin requested a review from a team as a code owner March 24, 2026 14:16
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 126f560

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 24, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

✅ All changesets look good

devin-ai-integration[bot]

This comment was marked as resolved.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 24, 2026

Let me think through the changes carefully:

  1. The core fix is correct: hasSsr() checks if ssr exists and is truthy before proceeding with SSR-specific configuration. This correctly prevents the crash reported in Wrangler fails during Angular setup with Cannot set properties of undefined (setting 'experimentalPlatform') #12950.

  2. The assert on line 76: After hasSsr() returns true, we know ssr is truthy. The assert is a good defensive guard, and the bracket notation ssr["experimentalPlatform"] is necessary because ssr is typed as Record<string, unknown> | false | null — after the assert, TypeScript narrows it to Record<string, unknown>, which works fine with bracket access.

  3. Type change: Making ssr optional in AngularJson type is correct.

  4. The angularJson object is parsed once and passed down to updateAngularJson — this is cleaner than re-reading the file. Good refactor.

  5. Test coverage: Tests cover non-SSR (no ssr field), ssr: false, and SSR-enabled cases. Dry-run tests included for both paths. This is solid coverage.

  6. Pre-existing issue (not introduced by this PR): The workerName / angular.json project name mismatch issue is pre-existing and actually exists in the old code too (line 72 in the old updateAngularJson also used projectName as a key). The new code's hasSsr() at least uses optional chaining so it won't crash — it'll just silently fall back to SPA mode. This is arguably better than the old behavior (which would crash). Not actionable for this PR review.

  7. BASE_OPTIONS.projectPath: Set to process.cwd() at module load time (not temp dir), but since projectPath is not used by Angular's configure() method, this is harmless. A minor test quality nit but not actionable.

The changes are clean, the fix is correct, the tests are thorough, and I don't see any logic bugs, security issues, or backward compatibility problems. The SSR path behavior is preserved exactly as before, and the new SPA path is a reasonable assets-only configuration.

LGTM

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 24, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13039

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13039

miniflare

npm i https://pkg.pr.new/miniflare@13039

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13039

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13039

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13039

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13039

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13039

wrangler

npm i https://pkg.pr.new/wrangler@13039

commit: 126f560

Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks Pete 😄

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 24, 2026
@petebacondarwin petebacondarwin merged commit bc24ec8 into main Mar 24, 2026
48 checks passed
@petebacondarwin petebacondarwin deleted the fix/angular-autoconfig-spa branch March 24, 2026 15:23
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Wrangler fails during Angular setup with Cannot set properties of undefined (setting 'experimentalPlatform')

3 participants