节点 cluster.isPrimary 未定义

bah*_*379 5 multithreading cluster-computing child-process node.js node-cluster

Node 说它cluster.isMaster已被弃用,我们应该使用cluster.isPrimary. 但是,虽然isMaster毫无问题地返回我 true,但当我undefined尝试时我得到cluster.isPrimary

const cluster = require("cluster");

console.log(cluster.isPrimary); /// undefined

console.log(cluster.isMaster); /// true

Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况?

Ion*_*Leu 5

使用节点 v16+ 并添加"esModuleInterop": true到文件中tsconfig.json


abo*_*eep 4

确保您的 Node 版本至少为 16.0.0

您可以通过在终端中运行以下命令来看到这一点:

node --version
Run Code Online (Sandbox Code Playgroud)