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

Not loading app.ts #338

Open
ghostlexly opened this issue Jun 26, 2023 · 1 comment
Open

Not loading app.ts #338

ghostlexly opened this issue Jun 26, 2023 · 1 comment

Comments

@ghostlexly
Copy link

ghostlexly commented Jun 26, 2023

Issue description

The app is not loaded when i require it in my main entry script.

I have 2 files:

  • server.ts - for running workers in cluster mode
  • app.ts - the file that serve the application data

Context

OS version (is it docker or host?), ts-node-dev version: Docker

Did you try to run with ts-node? : yes, it's working with ts-node

Did you try to run with --files option enabled? Yes

Did you try to run with --debug option enabled? Yes

Do you have a repro example (git repo) with simple steps to reproduce your problem?

const cluster = require("cluster");
const numCPUs = require("os").cpus().length;

/** Initiate a Cluster */
if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);

  // Fork worker processes
  for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on("online", (worker) => {
    console.log(`Worker ${worker.process.pid} is running`);
  });

  // Handle worker process exit and create a new one
  cluster.on("exit", (worker, code, signal) => {
    console.log(`Worker ${worker.process.pid} died`);
    cluster.fork();
  });
} else {
  require("./app"); // this is not loaded
}

My cli command:

ts-node-dev --respawn --transpile-only -r tsconfig-paths/register src/server.ts

Debug log:

gistique-backend-1  | [INFO] 10:33:58 Restarting: /usr/src/app/src/server.ts has been modified
logistique-backend-1  | [DEBUG] 10:33:58 /usr/src/app/src/server.ts compiled in 12 ms
logistique-backend-1  | [DEBUG] 10:33:58 Removing all watchers from files
logistique-backend-1  | [DEBUG] 10:33:58 Child is already stopped, probably due to a previous error
logistique-backend-1  | [DEBUG] 10:33:58 Starting child process -r /tmp/ts-node-dev-hook-7154198465957726.js -r tsconfig-paths/register /usr/src/app/node_modules/ts-node-dev/lib/wrap.js src/server.ts
logistique-backend-1  | [DEBUG] 10:33:58 /usr/src/app/src/server.ts added to watcher
logistique-backend-1  | [DEBUG] 10:31:51 /usr/src/app/src/server.ts added to watcher
logistique-backend-1  | [DEBUG] 10:31:51 /usr/src/app/src/app.ts added to watcher
@Emt-lin
Copy link

Emt-lin commented Jun 30, 2023

maybe this is a ts-node-dev's bug。

cluster.fork()’s process has trapped in a endless loop。detail:child-require-hook.ts#L62

ts-node-dev process struct:

  • Main process(ts-node-dev )
  • child process (detail: ts-node-dev fork)
    • your server.ts running in this process
  • cluster.fork()’s process(your server.ts fork)
    • when this process excute this code, Main process code can't recevie this signal,because this child process is ts-node-dev forked process,not your your server.ts forked process,so app.ts not compiled.

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

No branches or pull requests

2 participants