[英]Use worker_threads in combination with node (v11.15.0), webpack and typescript -> module not found
I'm writting a NodeJS application where I want to use worker_threads to get rid of a blocking I/O call _mfrc522.findCard()
by a third party module ( mfrc522-rpi
) which delays the request handling of a WebApi in the same application.我正在编写一个 NodeJS 应用程序,我想使用 worker_threads 来摆脱第三方模块(
mfrc522-rpi
)的阻塞 I/O 调用_mfrc522.findCard()
,这会延迟同一应用程序中 WebApi 的请求处理.
When I try to reference the worker_threads
module in my TypeScript file I get the following WebPack error message:当我尝试在 TypeScript 文件中引用
worker_threads
模块时,我收到以下 WebPack 错误消息:
const { Worker } = require('worker_threads');
ERROR in ./core/command-processing/rfid-command-processor.ts
Module not found: Error: Can't resolve 'worker_threads' in '/home/pi/leabox/src/core/command-processing'
@ ./core/command-processing/rfid-command-processor.ts 11:19-44
@ ./core/leabox-controller.ts
@ ./index.ts
But I'm able to execute the following command directly:但我可以直接执行以下命令:
node -e "require('worker_threads'); console.log('success');
Output: success
Output:
success
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.