Skip to content
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

Prerendering routes not working when switching from @angular-devkit/build-angular:application to @nx/angular:application #29276

Closed
2 of 4 tasks
webtsofficial opened this issue Dec 10, 2024 · 0 comments · Fixed by #29281
Assignees
Labels
scope: angular Issues related to Angular support in Nx type: bug

Comments

@webtsofficial
Copy link

Current Behavior

Versions:
Nx: 20.2.1
Angular: 19.0.4
When I create a new project with:

npx create-nx-workspace@latest test

  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Which stack do you want to use? · angular
✔ Integrated monorepo, or standalone project? · integrated
✔ Application name · frontend
✔ Which bundler would you like to use? · esbuild
✔ Default stylesheet format · scss
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · Yes

✔ Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application? · No

✔ Test runner to use for end to end (E2E) tests · playwright
✔ Which CI provider would you like to use? · skip
✔ Would you like remote caching to make your build faster? · skip

And setup prerendering like this:
apps/frontend/project.json

"targets": {
    "build": {
        "executor": "@angular-devkit/build-angular:application",
        "prerender": {
          "discoverRoutes": false,
          "routesFile": "apps/frontend/routes.txt"
        },
    },
}

apps/frontend/routes.txt

/
/home
/blog
/customers

It works fine:

nx build frontend

> nx run frontend:build:production

Browser bundles      
Initial chunk files   | Names                |  Raw size | Estimated transfer size
chunk-NN72D66U.js     | -                    | 159.05 kB |                46.74 kB
main-H6DOJEGB.js      | main                 |  90.77 kB |                23.22 kB
polyfills-FFHMD2TL.js | polyfills            |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles               |   0 bytes |                 0 bytes

                      | Initial total        | 284.34 kB |                81.24 kB

Lazy chunk files      | Names                |  Raw size | Estimated transfer size
chunk-KJJNDZN2.js     | nx-welcome-component |  74 bytes |                74 bytes


Server bundles       
Initial chunk files   | Names                |  Raw size
server.mjs            | server               |   1.34 MB |                        
chunk-XDR4RVNH.mjs    | -                    | 600.48 kB |                        
polyfills.server.mjs  | polyfills.server     | 268.60 kB |                        
chunk-5DWPOUBR.mjs    | -                    | 139.81 kB |                        
chunk-RFT6F4MJ.mjs    | -                    |  19.19 kB |                        
chunk-S6KH3LOX.mjs    | -                    |   2.77 kB |                        
main.server.mjs       | main.server          |   1.01 kB |                        

Lazy chunk files      | Names                |  Raw size
chunk-FE3ZEMPP.mjs    | xhr2                 |  12.07 kB |                        
chunk-GWOROCXO.mjs    | nx-welcome-component | 160 bytes |                        

Prerendered 4 static routes.
Application bundle generation complete. [2.441 seconds]

But as soon as I switch to the @nx/angular:appliation executor, it always only prerenders 0 routes suddenly:

apps/frontend/project.json

"targets": {
    "build": {
        "executor": "@nx/angular:application",
        "prerender": {
          "discoverRoutes": false,
          "routesFile": "apps/frontend/routes.txt"
        },
    },
}
nx build frontend

> nx run frontend:build:production

Browser bundles      
Initial chunk files   | Names                |  Raw size | Estimated transfer size
chunk-NN72D66U.js     | -                    | 159.05 kB |                46.74 kB
main-H6DOJEGB.js      | main                 |  90.77 kB |                23.22 kB
polyfills-FFHMD2TL.js | polyfills            |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles               |   0 bytes |                 0 bytes

                      | Initial total        | 284.34 kB |                81.24 kB

Lazy chunk files      | Names                |  Raw size | Estimated transfer size
chunk-KJJNDZN2.js     | nx-welcome-component |  74 bytes |                74 bytes


Server bundles       
Initial chunk files   | Names                |  Raw size
server.mjs            | server               |   1.34 MB |                        
chunk-XDR4RVNH.mjs    | -                    | 600.48 kB |                        
polyfills.server.mjs  | polyfills.server     | 268.60 kB |                        
chunk-5DWPOUBR.mjs    | -                    | 139.81 kB |                        
chunk-RFT6F4MJ.mjs    | -                    |  19.19 kB |                        
chunk-S6KH3LOX.mjs    | -                    |   2.77 kB |                        
main.server.mjs       | main.server          |   1.01 kB |                        

Lazy chunk files      | Names                |  Raw size
chunk-FE3ZEMPP.mjs    | xhr2                 |  12.07 kB |                        
chunk-GWOROCXO.mjs    | nx-welcome-component | 160 bytes |                        

Prerendered 0 static routes.
Application bundle generation complete. [1.947 seconds]

Expected Behavior

It should prerender the same amount of routes as in the case with the @angular-devkit/build-angular:application executor

GitHub Repo

https://github.com/webtsofficial/nx-ssr-prerender-bug

Steps to Reproduce

  1. npx create-nx-workspace@latest test
    NX Let's create a new workspace [https://nx.dev/getting-started/intro]
    ✔ Which stack do you want to use? · angular
    ✔ Integrated monorepo, or standalone project? · integrated
    ✔ Application name · frontend
    ✔ Which bundler would you like to use? · esbuild
    ✔ Default stylesheet format · scss
    ✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · Yes
    ✔ Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application? · No
    ✔ Test runner to use for end to end (E2E) tests · playwright
    ✔ Which CI provider would you like to use? · skip
    ✔ Would you like remote caching to make your build faster? · skip

  2. switch from @angular-devkit/build-angular:application to @nx/angular:application

  3. Configure prerendering with a routes.txt file:
    "prerender": {
    "discoverRoutes": false,
    "routesFile": "apps/frontend/routes.txt"
    },

  4. run the build command and se, that 0 routes were prerendered

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.18.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.8.2

nx (global)        : 20.0.0
nx                 : 20.2.1
@nx/js             : 20.2.1
@nx/jest           : 20.2.1
@nx/eslint         : 20.2.1
@nx/workspace      : 20.2.1
@nx/angular        : 20.2.1
@nx/devkit         : 20.2.1
@nx/eslint-plugin  : 20.2.1
@nx/playwright     : 20.2.1
@nx/vite           : 20.2.1
@nx/web            : 20.2.1
@nx/webpack        : 20.2.1
typescript         : 5.6.3
---------------------------------------
Registered Plugins:
@nx/playwright/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
angular-eslint : 19.0.1

Failure Logs

Package Manager Version

npm 10.8.2

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Dec 10, 2024
@leosvelperez leosvelperez self-assigned this Dec 10, 2024
leosvelperez added a commit that referenced this issue Dec 10, 2024
…tion executor correctly (#29281)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #29276
FrozenPandaz pushed a commit that referenced this issue Dec 10, 2024
…tion executor correctly (#29281)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #29276

(cherry picked from commit 7fca6e2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants