【问题标题】:typescript error - cannot find name 'process'打字稿错误 - 找不到名称“进程”
【发布时间】:2019-04-30 22:56:05
【问题描述】:

我正在使用 express+ typescript 设置一个新项目并面临 typescript 错误 - 找不到名称 'processs'

package.json

"dependencies": {
    "express": "^4.16.4",
    "nodemon": "^1.18.7",
    "tsc": "^1.20150623.0",
    "typescript": "^3.1.6"
  },
  "devDependencies": {
    "@types/express": "^4.16.0",
    "@types/mocha": "^5.2.5",
    "@types/node": "^10.12.10",
    "eslint": "^5.9.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-promise": "^4.0.1",
    "mocha": "^5.2.0",
    "supertest": "^3.3.0",
    "typescript-eslint-parser": "^21.0.1"
  }

我尝试关注solution 并添加了类型 配置文件

{
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "outDir": "dist",
      "sourceMap": true,
      "types": ["node"] -----
    },
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "node_modules"
    ]
}

但我仍然收到错误消息。我已经安装了 npm (6.4.1) 和 node (8.14.0) 来开始构建我的新项目。有人可以强调我做错了什么吗?

【问题讨论】:

    标签: node.js typescript express


    【解决方案1】:

    只是指出解决此问题似乎需要 @types/node dev 依赖项。至少,这就是我摆脱错误的原因。 – devklick 7 月 8 日 8:42

    pnpm i --save-dev @types/node
    

    【讨论】:

      【解决方案2】:

      确保您的tsconfig.app.json 文件中有"types": ["node"]。在tsconfig.json 中拥有它对我来说还不够(Angular 12)。

      {
        ...
        "compilerOptions": {
          ...
          "types": ["node"]
        },
       ...
      }
      
      

      【讨论】:

        【解决方案3】:

        您的新配置看起来不错。虽然,如果 typescript 语言服务器仍然使用以前版本的 tsconfig,您可能必须重新启动它。为了在 VS Code 中执行此操作,您可以使用 Ctrl+Shift+PReload WindowTypeScript: Restart TS server(如果可用)。

        您的依赖项中也不需要tsc 包,因为它现在已被弃用,而typescript 包附带tsc 可执行文件。

        【讨论】:

        猜你喜欢
        • 2017-06-18
        • 1970-01-01
        • 2023-03-17
        • 2017-12-01
        • 1970-01-01
        • 2018-11-09
        • 1970-01-01
        • 2018-07-23
        • 2017-11-09
        相关资源
        最近更新 更多