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

Server starts twice when running npx nx serve-ssr #29442

Closed
1 of 4 tasks
franklin7301 opened this issue Dec 20, 2024 · 1 comment · Fixed by #29447
Closed
1 of 4 tasks

Server starts twice when running npx nx serve-ssr #29442

franklin7301 opened this issue Dec 20, 2024 · 1 comment · Fixed by #29447
Assignees

Comments

@franklin7301
Copy link

Current Behavior

When running npx nx serve-ssr store, the server starts twice, causing conflicts and errors. This issue occurs because both server.ts and main.server.ts contain calls to the run() function, leading to the server being started twice.

Expected Behavior

The server should only start once when running npx nx serve-ssr store.

GitHub Repo

This issue was encountered while following the example from the NX documentation: Module Federation with SSR.

Steps to Reproduce

  1. Run npx create-nx-workspace@latest myorg --preset=apps
  2. nx add @nx/angular
  3. npx nx g @nx/angular:host apps/store --ssr --remotes=product,checkout
  4. Run npx nx serve-ssr store.
  5. Observe that the server starts twice.

Nx Report

Node           : 22.11.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.9.0

nx                     : 20.2.2
@nx/js                 : 20.2.2
@nx/eslint             : 20.2.2
@nx/workspace          : 20.2.2
@nx/angular            : 20.2.2
@nx/devkit             : 20.2.2
@nx/eslint-plugin      : 20.2.2
@nx/module-federation  : 20.2.2
@nx/web                : 20.2.2
@nx/webpack            : 20.2.2
typescript             : 5.6.3
---------------------------------------
Community plugins:
angular-eslint : 19.0.2

Failure Logs

E:\myorg>npx nx serve-ssr store

> nx run store:serve-ssr:development

****************************************************************************************
This is a simple server for use in testing or debugging Angular applications locally.
It hasn't been reviewed for security issues.

DON'T USE IT FOR PRODUCTION!
****************************************************************************************
- Generating browser application bundles (phase: setup)...
- Generating server application bundles (phase: setup)...
(node:12920) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
[ Module Federation Manifest Plugin ] Warn Manifest will use absolute path resolution via its host at runtime, reason: publicPath='auto'
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
- Copying assets...
✔ Copying assets complete.
- Generating index html...
✔ Server application bundle generation complete.
✔ Server application bundle generation complete.
✔ Index html generation complete.

Compiled successfully.
./node_modules/zone.js/fesm2015/zone-node.js:163
                        throw error;
                        ^
Error: listen EADDRINUSE: address already in use :::7795
    at Server.setupListenHandle [as _listen2] (node:net:1907:16)
    at listenInCluster (node:net:1964:12)
    at Server.listen (node:net:2066:7)
    at Function.listen (E:\monorepo\myorg\dist\apps\store\server\255.js:8404:24)
    at run (./apps/store/src/server.ts:57:10)
    at Module.5965 (./apps/store/src/server.ts:69:3)
    at module (./webpack/bootstrap:22:1)
    at module (./webpack/runtime/readFile%20chunk%20loading:59:1)
    at module (./webpack/runtime/readFile%20chunk%20loading:59:1)
    at <anonymous> (./webpack/runtime/startup%20entrypoint:6:1)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1943:8)
    at invokeTask (./node_modules/zone.js/fesm2015/zone-node.js:402:33)
    at runTask (./node_modules/zone.js/fesm2015/zone-node.js:159:47)
    at invokeTask (./node_modules/zone.js/fesm2015/zone-node.js:483:34)
    at apply (./node_modules/zone.js/fesm2015/zone-node.js:472:48)
    at data.args.<computed> (./node_modules/zone.js/fesm2015/zone-node.js:950:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 7795
}

Node.js v22.11.0

A server error has occurred.
node exited with 1 code.
** Angular Universal Live Development Server is listening on http://localhost:4200, open your browser on http://localhost:4200 **

Package Manager Version

No response

Operating System

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

Additional Information

No response

@Coly010 Coly010 self-assigned this Dec 20, 2024
Coly010 added a commit that referenced this issue Dec 20, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ash2k Mikhail Mazurskiy
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2025
isaacplmann pushed a commit that referenced this issue Feb 11, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ash2k Mikhail Mazurskiy
## Current Behavior
During the update to support Angular 19, the host and remote generators'
`updateSsrSetup` function was missed.

This led to the creation of a second `server.ts` file, which would
result in the node server trying to instantiate twice.

## Expected Behavior
Fix the path normalization dependent on angular major version to ensure
only one server will be instantiated.

## Related Issue(s)

Fixes #29442
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants