Skip to content

Angular v19 prerender uses the wrong package.json #29787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
its-dibo opened this issue Mar 9, 2025 · 2 comments
Open

Angular v19 prerender uses the wrong package.json #29787

its-dibo opened this issue Mar 9, 2025 · 2 comments

Comments

@its-dibo
Copy link

its-dibo commented Mar 9, 2025

Which @angular/* package(s) are the source of the bug?

ssr

Is this a regression?

No

Description

when running an angular app that uses AngularNodeAppEngine from "@angular/ssr/node" and outputMode set to server it reads imports from src/package.json which is set to be used in dist

package.json

"imports": {
    "#configs/*": "./browser/configs/*.js"
}

in the source code the configs folder is live in "src/configs" but copied at build time into "dist/browser/configs"
the same goes for many dynamic imports that assume the app runs inside the dist dir, i.e. the paths may be differ from the corresponding paths in the source code.

The prerender should run the same way as the original app runs i.e. from dist.

another thing, I cannot find an option to totally disable the prerendering as prerender: false now has no effect

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.2.1
Node: 22.12.0
Package Manager: npm 10.9.0
OS: linux x64

Angular: 19.2.1
... animations, build, cli, common, compiler, compiler-cli, core
... forms, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker, ssr

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1902.1
@angular-devkit/core         19.2.1
@angular-devkit/schematics   19.2.1
@angular/cdk                 19.2.2
@angular/material            19.2.2
@schematics/angular          19.2.1
rxjs                         7.8.2
typescript                   5.8.2
zone.js                      0.15.0
    

Anything else?

No response

angular.json
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "cms-ui": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular/build:application",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "browser": "src/main.ts",
            "polyfills": ["zone.js"],
            "tsConfig": "tsconfig.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/manifest.webmanifest",
              "src/scripts.mjs",
              "src/configs"
            ],
            "styles": ["src/styles.scss"],
            "scripts": [],
            "server": "src/main.server.ts",
            "outputMode": "server",
            "prerender": false,
            "ssr": {
              "entry": "src/server.ts"
            },
            "serviceWorker": "ngsw-config.json",
            "define": {},
            "namedChunks": true,
            "externalDependencies": ["#configs/*"]
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2m"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular/build:dev-server",
          "configurations": {
            "production": {
              "buildTarget": "cms-ui:build:production"
            },
            "development": {
              "buildTarget": "cms-ui:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular/build:extract-i18n",
          "options": {
            "buildTarget": "cms-ui:build"
          }
        },
        "test": {
          "builder": "@angular/build:karma",
          "options": {
            "polyfills": ["zone.js", "zone.js/testing"],
            "tsConfig": "tsconfig.spec.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/manifest.webmanifest",
              "src/scripts.mjs",
              "src/configs"
            ],
            "styles": ["src/styles.scss"],
            "scripts": []
          }
        }
      }
    }
  },
  "cli": {
    "analytics": false
  }
}
@JeanMeche JeanMeche transferred this issue from angular/angular Mar 9, 2025
@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely angular/build:application area: @angular/build labels Mar 10, 2025
@alan-agius4
Copy link
Collaborator

You're experiencing this issue due to route extraction.

As a workaround, try setting the environment variable NG_BUILD_PARTIAL_SSR=1. This will generate a partial manifest, but keep in mind that the manifest will be created at runtime on the first request—unless you're in a serverless or worker environment. In such cases, the manifest may be generated on every request, potentially impacting performance. Additionally, validation errors will surface at runtime instead of during the build process.

@its-dibo
Copy link
Author

I did some workarounds but I think those are not good practices

1- changed package.imports paths to be src/** then added a postbuild script to change them back to ./browser/** in dist/package.json

details

src/package.json

{
 imports:{
 "#configs/*": "./src/configs/*.js"
}
}

dist/package.json (using postbuild)

{
 imports:{
 "#configs/*": "./browser/configs/*.js"
}
}

src/configs are added to assets to be copied as assets

2- temporairly configured the path "**" in app.routes.ts to be RenderMode.Server to avoid prerendering them until I find a good solution

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

No branches or pull requests

2 participants