@ types / node安装打字稿版本不能find模块“child_process”

我发现节点的打字稿版本不幸的是它无法从节点包中find“child_process”模块。

在我的控制台中的错误消息是模块未find:错误:无法parsing'child_process'

当我浏览一些博客时,他们build议在你的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" ] } } 

为什么他们不注入这个节点模块? 我在tsconfig.json文件中做错了什么? 如果你能给予一点帮助,我将不胜感激。 提前致谢。

也许是path:

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

通常你的tsconfigsrc

更新:

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

相反,我相信这可能是一个Webpack的问题。

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

 target: 'node' 

更新2:

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

 node: { child_process: 'empty' }