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

ng build fails with: An error occurred while extracting routes. #28683

Closed
1 task done
json-derulo opened this issue Oct 22, 2024 · 5 comments · Fixed by #28689
Closed
1 task done

ng build fails with: An error occurred while extracting routes. #28683

json-derulo opened this issue Oct 22, 2024 · 5 comments · Fixed by #28689
Assignees
Labels

Comments

@json-derulo
Copy link

Command

build

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

19.0.0-next.9

Description

When running ng build on a freshly generated Angular 19 prerelease project, an error is thrown.

Minimal Reproduction

  • Run npx @angular/cli@next new and enable SSR
  • Run ng build

Exception or Error

✘ [ERROR] An error occurred while extracting routes.

Error: No handler function exported from /projects/ng19-test-proj/node_modules/@angular/build/src/utils/server-rendering/routes-extractor-worker.js
    at /projects/ng19-test-proj/node_modules/piscina/dist/worker.js:142:23

Your Environment

Angular CLI: 19.0.0-next.12
Node: 20.18.0
Package Manager: npm 10.9.0
OS: darwin x64

Angular: 19.0.0-next.10
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package Version

@angular-devkit/architect 0.1900.0-next.12
@angular-devkit/build-angular 19.0.0-next.12
@angular-devkit/core 19.0.0-next.12
@angular-devkit/schematics 19.0.0-next.12
@angular/cli 19.0.0-next.12
@angular/ssr 19.0.0-next.12
@schematics/angular 19.0.0-next.12
rxjs 7.8.1
typescript 5.6.3
zone.js 0.15.0

Anything else relevant?

No response

@alan-agius4
Copy link
Collaborator

Hi @json-derulo,

I am not able to reproduce the above error with the steps provided.

$ npx @angular/cli@next new ssr-test --ssr
Need to install the following packages:
@angular/[email protected]
CREATE ssr-test/README.md (1478 bytes)
CREATE ssr-test/.editorconfig (314 bytes)
CREATE ssr-test/.gitignore (587 bytes)
CREATE ssr-test/angular.json (2753 bytes)
CREATE ssr-test/package.json (1363 bytes)
CREATE ssr-test/tsconfig.json (915 bytes)
CREATE ssr-test/tsconfig.app.json (489 bytes)
CREATE ssr-test/tsconfig.spec.json (434 bytes)
CREATE ssr-test/.vscode/extensions.json (130 bytes)
CREATE ssr-test/.vscode/launch.json (470 bytes)
CREATE ssr-test/.vscode/tasks.json (938 bytes)
CREATE ssr-test/src/main.ts (250 bytes)
CREATE ssr-test/src/index.html (293 bytes)
CREATE ssr-test/src/styles.css (80 bytes)
CREATE ssr-test/src/main.server.ts (264 bytes)
CREATE ssr-test/src/server.ts (1785 bytes)
CREATE ssr-test/src/app/app.component.css (0 bytes)
CREATE ssr-test/src/app/app.component.html (19903 bytes)
CREATE ssr-test/src/app/app.component.spec.ts (922 bytes)
CREATE ssr-test/src/app/app.component.ts (304 bytes)
CREATE ssr-test/src/app/app.config.ts (438 bytes)
CREATE ssr-test/src/app/app.routes.ts (77 bytes)
CREATE ssr-test/src/app/app.config.server.ts (505 bytes)
CREATE ssr-test/src/app/app.routes.server.ts (166 bytes)
CREATE ssr-test/public/favicon.ico (15086 bytes)
✔ Packages installed successfully.
    Successfully initialized git.

$ ng build
Browser bundles      
Initial chunk files   | Names            |  Raw size | Estimated transfer size
main-B62CN3HO.js      | main             | 235.21 kB |                64.37 kB
polyfills-FFHMD2TL.js | polyfills        |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles           |   0 bytes |                 0 bytes

                      | Initial total    | 269.73 kB |                75.65 kB


Server bundles       
Initial chunk files   | Names            |  Raw size
chunk-3LUFOK6H.mjs    | -                | 851.12 kB |                        
server.mjs            | server           | 842.21 kB |                        
polyfills.server.mjs  | polyfills.server | 268.60 kB |                        
main.server.mjs       | main.server      |  18.65 kB |                        
chunk-PES6N7ZL.mjs    | -                |   3.37 kB |                        

Lazy chunk files      | Names            |  Raw size
chunk-G752ZPIS.mjs    | xhr2             |  12.06 kB |                        
chunk-FS7GGNWD.mjs    | xhr2             |  12.06 kB |                        

Prerendered 1 static route.
Application bundle generation complete. [11.851 seconds]

@alan-agius4 alan-agius4 added the needs: repro steps We cannot reproduce the issue with the information given label Oct 22, 2024
@json-derulo
Copy link
Author

json-derulo commented Oct 22, 2024

@alan-agius4 I copied the exact command you were using, still I'm getting the same error. I also tried running npx @angular/cli@next build, same result. ng build --verbose does not give more information. Any chance that this is only happening on MacOS? Here is my full output:

$ npx @angular/cli@next new ssr-test --ssr
✔ Which stylesheet format would you like to use? CSS             [ 
https://developer.mozilla.org/docs/Web/CSS                     ]
CREATE ssr-test/README.md (1478 bytes)
CREATE ssr-test/.editorconfig (314 bytes)
CREATE ssr-test/.gitignore (587 bytes)
CREATE ssr-test/angular.json (2753 bytes)
CREATE ssr-test/package.json (1363 bytes)
CREATE ssr-test/tsconfig.json (915 bytes)
CREATE ssr-test/tsconfig.app.json (489 bytes)
CREATE ssr-test/tsconfig.spec.json (434 bytes)
CREATE ssr-test/.vscode/extensions.json (130 bytes)
CREATE ssr-test/.vscode/launch.json (470 bytes)
CREATE ssr-test/.vscode/tasks.json (938 bytes)
CREATE ssr-test/src/main.ts (250 bytes)
CREATE ssr-test/src/index.html (293 bytes)
CREATE ssr-test/src/styles.css (80 bytes)
CREATE ssr-test/src/main.server.ts (264 bytes)
CREATE ssr-test/src/server.ts (1785 bytes)
CREATE ssr-test/src/app/app.component.css (0 bytes)
CREATE ssr-test/src/app/app.component.html (19903 bytes)
CREATE ssr-test/src/app/app.component.spec.ts (922 bytes)
CREATE ssr-test/src/app/app.component.ts (304 bytes)
CREATE ssr-test/src/app/app.config.ts (438 bytes)
CREATE ssr-test/src/app/app.routes.ts (77 bytes)
CREATE ssr-test/src/app/app.config.server.ts (505 bytes)
CREATE ssr-test/src/app/app.routes.server.ts (166 bytes)
CREATE ssr-test/public/favicon.ico (15086 bytes)
✔ Packages installed successfully.
    Successfully initialized git.

$ cd ssr-test
$ ng build

Browser bundles      
Initial chunk files   | Names            |  Raw size | Estimated transfer size
main-B62CN3HO.js      | main             | 235.21 kB |                64.37 kB
polyfills-FFHMD2TL.js | polyfills        |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles           |   0 bytes |                 0 bytes

                      | Initial total    | 269.73 kB |                75.65 kB


Server bundles       
Initial chunk files   | Names            |  Raw size
chunk-3LUFOK6H.mjs    | -                | 851.12 kB |                        
server.mjs            | server           | 842.21 kB |                        
polyfills.server.mjs  | polyfills.server | 268.60 kB |                        
main.server.mjs       | main.server      |  18.65 kB |                        
chunk-PES6N7ZL.mjs    | -                |   3.37 kB |                        

Lazy chunk files      | Names            |  Raw size
chunk-G752ZPIS.mjs    | xhr2             |  12.06 kB |                        
chunk-FS7GGNWD.mjs    | xhr2             |  12.06 kB |                        

Prerendered 0 static routes.
Application bundle generation failed. [25.262 seconds]

✘ [ERROR] An error occurred while extracting routes.

Error: No handler function exported from/projects/ssr-test/node_modules/@angular/build/src/utils/server-rendering/routes-extractor-worker.js
    at /projects/ssr-test/node_modules/piscina/dist/worker.js:142:23

@json-derulo
Copy link
Author

@alan-agius4 I verified that it's only an issue with MacOS in a reproduction repository. In the following GitHub actions run you can see that the build succeeds on Ubuntu and Windows, but fails on MacOS.

@alan-agius4
Copy link
Collaborator

Umm… interesting @json-derulo, thanks for checking, I’ll take a look tomorrow.

@alan-agius4 alan-agius4 removed the needs: repro steps We cannot reproduce the issue with the information given label Oct 22, 2024
@alan-agius4 alan-agius4 self-assigned this Oct 22, 2024
@alan-agius4 alan-agius4 added needs: investigation Requires some digging to determine if action is needed angular/build:application area: @angular/build labels Oct 22, 2024
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Oct 23, 2024

It turns out the issue is related to the Node.js version. It seems there have been subtle changes in the ESM loader hooks. I’ll have a fix ready soon.

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely severity5: regression and removed needs: investigation Requires some digging to determine if action is needed labels Oct 23, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Oct 23, 2024
… prerendering or SSR

In Node.js 20, changes to ESM loader hooks result in the `--import` execArgv being passed from the parent to child workers.

This commit resolves the issue by setting an empty `execArgv` in the JavaScript transformer, preventing unintended propagation.

Closes angular#28683
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Oct 23, 2024
… prerendering or SSR

In Node.js 20, changes to ESM loader hooks result in the `--import` execArgv being passed from the parent to child workers.

This commit resolves the issue by setting an empty `execArgv` in the JavaScript transformer, preventing unintended propagation.

Closes angular#28683

(cherry picked from commit cc345b0)
alan-agius4 added a commit that referenced this issue Oct 23, 2024
… prerendering or SSR

In Node.js 20, changes to ESM loader hooks result in the `--import` execArgv being passed from the parent to child workers.

This commit resolves the issue by setting an empty `execArgv` in the JavaScript transformer, preventing unintended propagation.

Closes #28683

(cherry picked from commit cc345b0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants