0

My NestJS application compiles my Typescript worker

async function bootstrap(job: Job, done: DoneCallback) {
  //...
}
export default bootstrap;

into a js file with following line:

exports["default"] = bootstrap;

But Bull.js is throwing the following error:

/usr/src/app/node_modules/bull/lib/job.js:516
          reject(new Error(failedReason));
                 ^
Error: origProcessor.apply is not a function

It only works if I manually add into the compiled js file:

module.exports = bootstrap;

Does anyone know how to properly config webpack to get it? I'd like to keep using webpack since all projects are using it.

Additional info:

  • bull version: 4.10.4;
  • webpack version: 5.76.3;
  • nestjs version: 9.3.12;
Nícolas Amarante
  • 165
  • 1
  • 1
  • 7

1 Answers1

0

Found out by deeply reading the docs from webpack and debugging master.js in bull package.

Just add commonjs as library target in webpack config:

module.exports = {
output: {
  //filename: ...
  //path: ...
  library: {
    type: 'commonjs-module',
  },
 }
}

The compiled js file will have this line:

module.exports = __webpack_exports__;
Nícolas Amarante
  • 165
  • 1
  • 1
  • 7