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

worker processes in cluster mode does not use the specified project file #367

Closed
gfx opened this issue Jun 21, 2017 · 5 comments
Closed
Labels
research Needs design work, investigation, or prototyping. Implementation uncertain.

Comments

@gfx
Copy link
Contributor

gfx commented Jun 21, 2017

demo: https://github.com/gfx/ts-node-with-cluster-bugs

I found that the worker processes spawned by cluster module are not compiled in our environments, where tsconfig.json specifies "module": "es2015" and tsconfig.universal.json specifies "modules": "commonjs".

This is because the worker processes always refer tsconfig.json which compiles *.ts for webpack, not nodejs.

FYI: I have avoided this issue by creating tsconfig.json for nodejs and tsconfig.webpack.json for webpack.

@blakeembrey
Copy link
Member

Any thoughts on how you think we could solve this correctly? It'll always be an issue when forking another process to do work, so I'd love to hear your thoughts.

@blakeembrey blakeembrey added the research Needs design work, investigation, or prototyping. Implementation uncertain. label Sep 14, 2017
@progral
Copy link

progral commented Jan 5, 2018

//some imports
const PATH_TO_NODE = __dirname + '/../node_modules/.bin/ts-node'; 
cluster.setupMaster({
    execArgv: [PATH_TO_NODE, '-r', 'tsconfig-paths/register'], //install tsconfig-paths before
} as cluster.ClusterSettings)
//rest of cluster.ts

works except port sharing, what is the main reason for a cluster...... So it is useless. There is a EADDRINUSE error with this. Nevertheless the cluster starts and works well.

I have no idea why. execArgv works, because it should give some arguments to forked node, only. Seems it starts ts-node. Looks like without that the forks are not compiled, so node is complaining about invalid "import" syntax? Just walking into dark....

@progral
Copy link

progral commented Jan 5, 2018

ok, after doing some research if found out that you have to do this:

//some import
cluster.setupMaster({
    execArgv: ['-r', 'tsconfig-paths/register', '-r', 'ts-node/register']
} as cluster.ClusterSettings)
cluster.fork()

I will create a gist tomorrow.

@progral
Copy link

progral commented Jan 14, 2018

To close this issue I suggest to document the need of the parameters in execArgv for clusters . It works like a charme in one of my production apps @blakeembrey

@cspotcode
Copy link
Collaborator

I tested this reproduction on the latest ts-node. We set execArgv correctly thanks to #1657, so this is fixed and works out-of-the-box. Users do not need to set execArgv manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research Needs design work, investigation, or prototyping. Implementation uncertain.
Projects
None yet
Development

No branches or pull requests

4 participants