bull
bull copied to clipboard
Separate process worker not using TypeScript config
Description
I'm trying to import my modules in a separate process (using queue.process("path/to/processor.ts")
) using TypeScript.
I get this error as soon as I try importing a module that is aliased using tsconfig-paths
in the process file:
I need tsconfig-paths
as it is what my entire application is using, is there a way to configure how the process is spawned, preferrably so I can set it to use my tsconfig.json
?
Test code to reproduce
processor.ts
import { something } from "aliased/modules"
Bull version
3.3.10
I cannot think about a workaround for this right now other than building the .ts file and use the .js file as a processor. A bit more inconvenient but with a proper build setup it should be achievable.
Hi folks! Do you have any news?
@Nemmo you should build your processor and use the built .js file, that is the only solution that will work for some time.
@manast If there was a way to specify how the process is spawned (command arguments?) then this problem would be easier to solve, at least with tsconfig-paths.
@manast If there was a way to specify how the process is spawned (command arguments?) then this problem would be easier to solve, at least with tsconfig-paths.
We could use node's -r
to specify @babel/register
or any other thing that transforms files when required.
I believe we need to call @babel/register
before https://github.com/OptimalBits/bull/blob/10a9eae35abb7ac8af952182409db3f83b9ff474/lib/process/master.js#L36-L37
I can't call @babel/register
inside the processor script. it won't work, I'm not strong with the intricacy of babel-node
but I could get it working by adding this line in master.js
this:
process.on('message', function(msg) {
switch (msg.cmd) {
case 'init':
// this line
require('@babel/register').default({ extensions: [".js",".jsx",".ts",".tsx"] });
processor = require(msg.value);
if (processor.default) {
// support es2015 module.
processor = processor.default;
}
// ...
}
}
This is originally passed in babel-node --extensions ".js",".jsx",".ts",".tsx" scheduler.js
The fork is not inheriting the original arguments.
For now, I'll have to use a patch it this way to make it still work for me in development.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.