Bull: TypeScript processors are not working anymore

Created on 3 Sep 2018  Â·  8Comments  Â·  Source: OptimalBits/bull

Prior to version 3.4.7 I could use .ts file as separate thread processor.
In version 3.4.8 this is impossible, I guess, because of this line

handler + (path.extname(handler) === '.js' ? '' : '.js');

So now I get error

File .../index.ts.js does not exist

bug

Most helpful comment

Seems like an easy fix, will try to make it ASAP.

All 8 comments

interesting, but the .ts file is not really a typescript file right?

No, this is actually a TypeScript file, even with Interfaces in it (I describe Job's parameters) and it exports processor like this

export default async function(job: Job<JobInterface>) { ... }

I'm not sure, how this works, but Bull launches this processor via typescript without problems, if I look through ps, there will be something like

/usr/local/Cellar/node/10.9.0/bin/node /.../node_modules/ts-node/dist/bin.js /.../node_modules/bull/lib/process/master.js

I have two environments, development and production.
In dev mode application is launched using nodemon with ts-node.
After build application is launched as usual node application, there is no .ts files in build.

hmm, ok, so you launch the main application with ts-node, but I still find interesting that it works to spawn a new subprocess and require a .ts file without any errors, could you provide a minimal test case for this please?

Sure → https://github.com/victordidenko/ts-bull-error

Try

yarn
yarn start

It will output (at least for me, I'm not sure anymore in anything)

# yarn start
yarn run v1.9.4
$ ts-node src/main.ts
I'm working
Create bull queue
Add job to bull queue
Job 1 in pid 15361 got data: { text: 'hello, world!' }

You can also build and launch with node with

yarn build
yarn prod

Then, try to upgrade bull from 3.4.7 to 3.4.8 and repeat yarn start – it will fail with error

# yarn start
yarn run v1.9.4
$ ts-node src/main.ts
I'm working
Create bull queue

.../ts-bull-error/node_modules/bull/lib/queue.js:669
      throw new Error('File ' + processorFile + ' does not exist');
            ^
Error: File .../ts-bull-error/src/processor.ts.js does not exist
    at Queue.setHandler (.../ts-bull-error/node_modules/bull/lib/queue.js:669:13)
    at Queue.process (.../ts-bull-error/node_modules/bull/lib/queue.js:637:8)
    at Object.<anonymous> (.../ts-bull-error/src/main.ts:11:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Module.m._compile (.../ts-bull-error/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.require.extensions.(anonymous function) [as .ts] (.../ts-bull-error/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at Object.<anonymous> (.../ts-bull-error/node_modules/ts-node/src/bin.ts:157:12)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
error Command failed with exit code 1.

But

yarn build
yarn prod

will work, because processor now JS file

@victordidenko Thanks for catching that problem with 3.4.8, but also for pointing me into the right direction how to use typescript files with external processors in Bull. I did not manage to make this work some time ago but with your example, I got it implemented - using Bull 3.4.7 that is of course.

-act

Hey @actraiser @manast , Is there any update?
Do you really need this line?
var processorFile = handler + (path.extname(handler) === '.js' ? '' : '.js');
Is there any suggestion to get rid of this particular problem?

Seems like an easy fix, will try to make it ASAP.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSRossiter picture JSRossiter  Â·  3Comments

sarneeh picture sarneeh  Â·  3Comments

alolis picture alolis  Â·  4Comments

weeco picture weeco  Â·  3Comments

sibelius picture sibelius  Â·  3Comments