打字稿找不到模块“worker_threads”

问题描述

我正在尝试在 Node v14.15.1 中使用 node.js 'worker_threads' 库并收到此错误

Cannot find module 'worker_threads' or its corresponding type declarations.ts(2307)
tsc 

src/api/services/email.service.ts:1:62 - error TS2307: Cannot find module 'worker_threads'.

1 import { Worker,isMainThread,parentPort,workerData } from 'worker_threads';
                                                              

Found 1 error.

我的代码 -

import { Worker,workerData } from 'worker_threads';

工作线程在节点 11 之后变得稳定。所以它应该可以工作。 我做错了什么?

PS - 我用 JS 运行了相同的代码,它运行良好,所以我不认为它的 Node.js 问题。其他核心库如 fs 也工作正常。我需要为 TS 做任何额外的配置吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)