gpt4 book ai didi

node.js - @types/node 安装的 typescript 版本找不到模块“child_process”

转载 作者:太空狗 更新时间:2023-10-29 17:26:03 26 4
gpt4 key购买 nike

我找到了 node 的 typescript 版本不幸的是,它无法从 Node 包中找到 “child_process” 模块。

确切地说,我的控制台中的错误消息是找不到模块:错误:无法解析“child_process”

当我浏览一些博客时,他们建议在您的 tsconfig.json 文件中添加以下代码。

"typeRoots": [
"node_modules/@types"
]

我在此处粘贴的内容不太可能没有帮助。

tsconfig.json

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}

为什么他们不注入(inject)这个 Node 模块?我在 tsconfig.json 文件中做错了什么吗?如果您能提供一点帮助,我将不胜感激。提前致谢。

最佳答案

也许是路径:

"typeRoots": [
"../node_modules/@types"
]

通常您在 src 中有您的 tsconfig

更新:

我原来的回答没有意义,因为你有这个 "baseUrl": "src"

相反,我认为这可能是 Webpack 的问题。

尝试将此添加到您的 webpack.config 文件中:

target: 'node'

更新 2:

解决方法:将以下内容添加到您的配置文件中:

node: {
child_process: 'empty'
}

关于node.js - @types/node 安装的 typescript 版本找不到模块“child_process”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44305603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com