简体   繁体   English

结合 node (v11.15.0)、webpack 和 typescript 使用 worker_threads -> 找不到模块

[英]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

  • Node version: 11.15.0节点版本:11.15.0
  • WebPack version: 4.41.2 WebPack 版本:4.41.2
  • TypeScript version: 3.6.4 TypeScript 版本:3.6.4

Activating experimental worker support for node.js via the command line before starting the application solved the issue for me:在启动应用程序之前通过命令行激活对 node.js 的实验性工作人员支持解决了我的问题:

export NODE_OPTIONS=--experimental-worker

Please check this thread for further information.请检查此线程以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Typescript 找不到模块“worker_threads” - Typescript cannot find module 'worker_threads' 无法使用 node:worker_threads 调试打字稿项目,找不到模块错误 - Unable to debug typescript project with node:worker_threads, cannot find module error 找不到此依赖项:* worker_threads - This dependency was not found: * worker_threads 同时使用 Node.js PM2 集群和 Node.js worker_threads 模块的最有效方法是什么? - Most efficient way to use Node.js PM2 clustering and Node.js worker_threads module at the same time? 节点 worker_threads + 集群 + 亲和性 - Node worker_threads + cluster + affinity 在 Electron 应用程序中,使用 webpack/electron-builder 到 package 后,在 worker_threads 提示 MODULE_NOT_FOUND 中需要第三方模块 - In Electron app, after using webpack/electron-builder to package, require third-party module in worker_threads prompts MODULE_NOT_FOUND 已知 NPM 不能在 Node.js v11.15.0 上运行我正在研究 angular js 所以不能降低版本? 该怎么办? - NPM is known not to run on Node.js v11.15.0 I am working on angular js so cant lower version? what to do? 如何在 Sapper 上使用 worker_threads? - How to use worker_threads on Sapper? 与nodejs worker_threads模块一起使用时广播频道问题 - Issue with broadcast channel when using with nodejs worker_threads module 在生产中找不到模块“worker_threads”错误 - Cannot find module 'worker_threads' error in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM