bull icon indicating copy to clipboard operation
bull copied to clipboard

Separate process worker not using TypeScript config

Open Enitoni opened this issue 6 years ago • 7 comments

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: Image

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

Enitoni avatar Apr 09 '18 22:04 Enitoni

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.

manast avatar Apr 16 '18 20:04 manast

Hi folks! Do you have any news?

CTOlet avatar May 25 '18 13:05 CTOlet

@Nemmo you should build your processor and use the built .js file, that is the only solution that will work for some time.

manast avatar May 25 '18 13:05 manast

@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.

Enitoni avatar May 27 '18 11:05 Enitoni

@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.

gcangussu avatar Jul 25 '19 14:07 gcangussu

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.

lxcid avatar Apr 28 '20 14:04 lxcid

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.

stale[bot] avatar Jul 12 '21 17:07 stale[bot]