我正在尝试将 node.js 'worker_threads' 库与 Node v14.15.1 一起使用并收到此错误
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, isMainThread, parentPort, workerData } from 'worker_threads';
工作线程在节点 11 之后变得稳定。所以它应该可以工作。我究竟做错了什么 ?
PS - 我用 JS 运行了相同的代码,它运行良好,所以我不认为它的 Node.js 问题。fs 等其他核心库也运行良好。我需要为 TS 做任何额外的配置吗?