英文:
Bull.js is not getting the exported function in NestJS with webpack
问题
My NestJS application compiles my Typescript worker into a js file with the following line:
exports["default"] = bootstrap;
但是 Bull.js 报错如下:
/usr/src/app/node_modules/bull/lib/job.js:516
reject(new Error(failedReason));
^
Error: origProcessor.apply is not a function
只有在我手动添加以下内容到编译后的 js 文件中时才能正常工作:
module.exports = bootstrap;
有人知道如何正确配置 webpack 以解决这个问题吗?我想继续使用 webpack,因为所有项目都在使用它。
附加信息:
- bull 版本:4.10.4;
- webpack 版本:5.76.3;
- nestjs 版本:9.3.12;
英文:
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;
答案1
得分: 0
通过深入阅读webpack文档和调试bull包中的master.js文件发现。
只需在webpack配置中将commonjs作为库目标添加:
module.exports = {
output: {
//filename: ...
//path: ...
library: {
type: 'commonjs-module',
},
}
}
编译后的js文件将包含以下行:
module.exports = __webpack_exports__;
英文:
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__;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论