@ types/node安装的打字稿版本无法找到模块" child_process" [英] @types/node installed typescript version not able find module" child_process"
问题描述
很遗憾,我找到了 node 的打字稿版本,它找不到节点软件包中的"child_process" 模块.
I found typescript version for node unfortunately it's not able find "child_process" module from the node packages.
确实是我的控制台中的错误消息是未找到模块:错误:无法解析'child_process'
Exactly the error message in my console is Module not found: Error: Can't resolve 'child_process'
当我浏览一些博客时,他们建议在您的 tsconfig.json 文件中添加以下代码.
When I went through some blog they recommended to add below code in your tsconfig.json file.
"typeRoots": [
"node_modules/@types"
]
与我在此处粘贴的内容不太一样,这没有帮助.
Same thing as I pasted over here unlikely it's did't help.
tsconfig.json
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"
]
}
}
为什么他们不注入该节点模块?我在tsconfig.json文件中做错了吗?如果您能提供一点帮助,我将不胜感激. 预先感谢.
Why they don't inject this node module ? Am I doing something wrong in tsconfig.json file? I would be a grateful if you could give a little help. Thanks in advance.
推荐答案
也许是路径:
"typeRoots": [
"../node_modules/@types"
]
通常,您在src
中具有 tsconfig .
更新:
我的原始答案没有任何意义,因为您有这个"baseUrl": "src"
.
My original answer makes no sense, because you have this "baseUrl": "src"
.
相反,我认为这可能是Webpack的问题.
As instead, I believe it could be a Webpack issue.
尝试将其添加到您的 webpack.config 文件中:
Try adding this to your webpack.config file:
target: 'node'
更新2:
解决方法:将以下内容添加到您的配置文件中:
Workaround: Add the following to your config file:
node: {
child_process: 'empty'
}
这篇关于@ types/node安装的打字稿版本无法找到模块" child_process"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!