模块“node:process”"没有导出的成员“dlopen”

qnakjoqk  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(102)

我在index.ts中的Typescript项目([[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) , [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) , @types/ [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection))中有以下代码:

import { dlopen } from "node:process";

字符串
nodemon index.ts运行成功(我的本地插件加载并执行)
但是,tsc在使用error TS2339: Property 'dlopen' does not exist on type 'Process'时失败
我看了一下,发现dlopen实际上不存在于node_modules/@types/node/process.d.tshttps://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v18/process.d.ts)中,甚至不出现在整个本地和全局node_modules中(文本搜索已经完成)。
我猜dlopen必须以某种方式存在于nodejs运行时,这就是为什么nodemon index.ts工作,但它的类型定义不存在。
如何解决/解决这个问题?

noj0wjuj

noj0wjuj1#

您可以尝试在项目中为dlopen函数添加新的本地types.d.ts声明文件:

declare module 'process' {
  export function dlopen<T = any>(module: any, filename: string, flags?: any): T;
}

字符串

相关问题