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

express app "serve" fails (in docker) when dependant on js lib built with tsc #17608

Closed
1 of 4 tasks
donatcranburi opened this issue Jun 14, 2023 · 5 comments
Closed
1 of 4 tasks

Comments

@donatcranburi
Copy link

donatcranburi commented Jun 14, 2023

Current Behavior

I was attempting to move my dev environment into docker and setup a little alpine image that basically just installs node and runs npx nx serve webserver.

The server was crashing with an error watch error: Daemon closed the connection.

Bashed my head against google a bit, tried disabling the nx_dameon, clearing node_modules, nx resettin, etc, to no avail. Started a repro repo and was able to get a minimal reproduction up. Seems like if I have an app built with @nx/express, that imports a lib built with @nx/js and using tsc as the builder, then I can reproduce the issue.

If I instead use a lib generated for node, or js with none selected as the builder, everything is fine.

Nothing I need resolved as I just moved my shared library to one without a build step, but figured I'd post it up since I had the reproduction lying around.

Expected Behavior

I'd have expected the "express" app to be able to be served regardless of its dependency on a js lib built with a tsc build step.

GitHub Repo

https://github.com/donatcranburi/nx-repro-docker-crash

Steps to Reproduce

Nx Report

>  NX  Falling back to ts-node for local typescript execution. This may be a little slower.
  - To fix this, ensure @swc-node/register and @swc/core have been installed

 >  NX   Report complete - copy this into the issue template

   Node   : 18.9.0
   OS     : linux x64
   yarn   : 1.22.19
   Hasher : Native
   
   nx                 : 16.3.2
   @nx/js             : 16.3.2
   @nx/jest           : 16.3.2
   @nx/linter         : 16.3.2
   @nx/workspace      : 16.3.2
   @nx/devkit         : 16.3.2
   @nx/eslint-plugin  : 16.3.2
   @nx/express        : 16.3.2
   @nx/node           : 16.3.2
   @nrwl/tao          : 16.3.2
   @nx/webpack        : 16.3.2
   typescript         : 5.0.4
   ---------------------------------------
   Local workspace plugins:
   	 @test-nx-express/test-js-lib

Failure Logs

test-nx-express  | 
test-nx-express  | > nx run test-nx-express:serve:development
test-nx-express  | 
test-nx-express  | Debugger listening on ws://localhost:9229/87a30f57-8a9a-4f85-a7b5-7ccd2be0c51b
test-nx-express  | For help, see: https://nodejs.org/en/docs/inspector
test-nx-express  | 
test-nx-express  | Listening at http://localhost:3333/api
test-nx-express  | 
test-nx-express  | >  NX  File change detected. Restarting...
test-nx-express  | 
test-nx-express  | Watch error: Daemon closed the connection
test-nx-express  | 
test-nx-express  |  
test-nx-express  | 
test-nx-express  |  >  NX   Running target serve for project test-nx-express failed
test-nx-express  | 
test-nx-express  |    Failed tasks:
test-nx-express  |    
test-nx-express  |    - test-nx-express:serve:development
test-nx-express  |    
test-nx-express  |    Hint: run the command with --verbose for more details.
test-nx-express  | 
test-nx-express exited with code 1

Operating System

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

Additional Information

No response

@donatcranburi donatcranburi changed the title express app "serve" fails when dependant on js lib built with tsc express app "serve" fails (in docker) when dependant on js lib built with tsc Jun 14, 2023
@xendarboh
Copy link

xendarboh commented Jun 16, 2023

Similar experience. Tried disabling the nx_dameon, could not.
Using Docker FROM node:lts-slim.

Thinking... nx watcher uses @parcel/watcher which has a reported container-related issue:
Crash when running in alpine podman container · Issue #141 · parcel-bundler/watcher

Q: (Besides the watcher not being disabled) Does parcel/watcher have a problem running inside the container?
A: Maybe:

  • installed watchman in the Dockerfile apt-get install watchman, as watchman is one of the Linux backends parcel/watcher supports (the other being inotify)
  • and the nature of the error message changed
  • but the service still did not start

No watchman installed:

api-server     | npm verb cli /usr/local/bin/node /usr/local/bin/npm
api-server     | npm info using [email protected]
api-server     | npm info using [email protected]
api-server     | npm verb title npm run prod-start-api-server
api-server     | npm verb argv "run" "prod-start-api-server" "--watch" "false" "--loglevel" "verbose"
api-server     | npm verb logfile logs-max:10 dir:/home/node/.npm/_logs/2023-06-16T16_10_50_115Z-
api-server     | npm verb logfile /home/node/.npm/_logs/2023-06-16T16_10_50_115Z-debug-0.log
api-server     | 
api-server     | > [email protected] prod-start-api-server
api-server     | > prisma migrate deploy && NODE_ENV=production nx run api-server:serve:production
api-server     | 
api-server     | Prisma schema loaded from libs/prisma/schema.prisma
api-server     | Datasource "db": PostgreSQL database "postgres", schema "public" at "postgres:5432"
api-server     | 
api-server     | 4 migrations found in prisma/migrations
api-server     | 
api-server     | 
api-server     | No pending migrations to apply.
api-server     | 
api-server     | > nx run api-server:serve:production
api-server     | 
api-server     | 
api-server     | >  NX  File change detected. Restarting...
api-server     | 
api-server     | Watch error: Daemon closed the connection
api-server     | 
api-server     |  
api-server     | 
api-server     |  >  NX   Running target serve for project api-server failed
api-server     | 
api-server     |    Failed tasks:
api-server     |    
api-server     |    - api-server:serve:production
api-server     |    
api-server     |    Hint: run the command with --verbose for more details.
api-server     | 
api-server     | npm verb exit 1
api-server     | npm verb code 1
api-server exited with code 1
dependency failed to start: container api-server is unhealthy

With watchman installed:
(which slows startup time, btw)

api-server     | npm verb cli /usr/local/bin/node /usr/local/bin/npm
api-server     | npm info using [email protected]
api-server     | npm info using [email protected]
api-server     | npm verb title npm run prod-start-api-server
api-server     | npm verb argv "run" "prod-start-api-server" "--watch" "false" "--loglevel" "verbose"
api-server     | npm verb logfile logs-max:10 dir:/home/node/.npm/_logs/2023-06-16T17_05_19_652Z-
api-server     | npm verb logfile /home/node/.npm/_logs/2023-06-16T17_05_19_652Z-debug-0.log
api-server     | 
api-server     | > [email protected] prod-start-api-server
api-server     | > prisma migrate deploy && NODE_ENV=production nx run api-server:serve:production
api-server     | 
api-server     | Prisma schema loaded from libs/prisma/schema.prisma
api-server     | Datasource "db": PostgreSQL database "postgres", schema "public" at "postgres:5432"
api-server     | 
api-server     | 4 migrations found in prisma/migrations
api-server     | 
api-server     | 
api-server     | No pending migrations to apply.
api-server     | 
api-server     | > nx run api-server:serve:production
api-server     | 
api-server     | 
api-server     |  
api-server     | 
api-server     |  >  NX   Successfully ran target serve for project api-server
api-server     | 
api-server     | 
api-server     | npm verb exit 0
api-server     | npm info ok 
dependency failed to start: container api-server is unhealthy

So, the nature of the issue changed... at least by the output, but still no running service. Which, for this project, could be related to something else? like #10296

@xendarboh
Copy link

xendarboh commented Jun 16, 2023

Note: I experience this issue to be introduced somewhere between
nx 16.0.2 (works !) and nx 16.3.2 (! works).

(nx migrate and update deps)

@xendarboh
Copy link

update: made a number of changes including nx migrate, more cjs-->esm (back to esbuild from webpack), and still found this error: Watch error: Daemon closed the connection.

I was able to resolve it by removing a docker volume on the failing service. Unknown why something is watching, why watcher could not be disabled, or why it errors in the way it does.

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

github-actions bot commented Feb 4, 2024

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 Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants