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 · 0 comments · 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 · 0 comments · 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

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

Successfully merging a pull request may close this issue.

2 participants