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

标签 node.js angular

我找到了 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/

相关文章:

javascript - JWT.decode 返回 null

javascript - typescript 滚动位置

angular - cellRendererFramework 未找到组件工厂 ag-grid angular2

node.js - AWS Lambda 不通过 nodemailer 触发电子邮件,但在本地开发环境中触发

javascript - Node.js 中的函数构造函数是什么?

javascript - ES6 对象中的 setInterval

angular - 如何仅为特定路线激活 RouteReuseStrategy

Angular2 - 如何从应用程序外部调用组件功能

angular - 当选项具有条件名称时如何按字母顺序排序垫选择

node.js - libuv 和 Node.js 实际上是如何调度定时器的?