【问题标题】:TS2688: Cannot find type definition file for 'node' with @types/node installedTS2688:找不到安装了 @types/node 的“节点”的类型定义文件
【发布时间】:2018-06-05 10:14:09
【问题描述】:

我很难在 Heroku 上构建 TypeScript 应用程序。

我的依赖项列表包括我正在使用的所有包的类型定义:

"dependencies": {
    "@nestjs/common": "^4.5.1",
    "@nestjs/core": "^4.5.1",
    "@nestjs/microservices": "^4.5.1",
    "@nestjs/testing": "^4.5.1",
    "@nestjs/websockets": "^4.5.1",
    "@types/express": "^4.0.39",
    "@types/jest": "^21.1.8",
    "@types/json-schema": "^6.0.0",
    "@types/jsonwebtoken": "^7.2.5",
    "@types/mongoose": "^4.7.29",
    "@types/node": "^8.5.1",
    "@types/passport": "^0.4.2",
    "@types/passport-jwt": "^3.0.0",
    "@types/supertest": "^2.0.4",
    "chalk": "^2.3.0",
    "dotenv": "^4.0.0",
    "express-jwt": "^5.3.0",
    "global": "^4.3.2",
    "jsonwebtoken": "^8.1.0",
    "mongoose": "^4.13.7",
    "passport": "^0.4.0",
    "passport-jwt": "^3.0.1",
    "redis": "^2.8.0",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.5.5",
    "tslint": "^5.8.0",
    "ts-node": "^4.0.2",
    "typescript": "^2.6.2"
  },

但是,在 Heroku 上构建时,我得到:

error TS2688: Cannot find type definition file for 'node'
error TS2307: Cannot find module 'http'

等等。我的 tsconfig.json 将 typeRoots 设置为 './node_modules/@types' 并且我在本地成功构建。

为什么 Heroku 找不到这些类型?

【问题讨论】:

    标签: node.js typescript heroku


    【解决方案1】:

    显然 Heroku 没有对我的 package.json 文件进行更改,或者缓存了构建过程的某些部分,这些部分排除了我从 devDependencies 移动到依赖项的 @type 定义。

    我这样清除了构建缓存:

    $ heroku plugins:install heroku-repo
    $ heroku repo:purge_cache -a [appname]
    $ git commit --allow-empty -m "Purge cache"
    $ git push heroku master
    

    一切都按预期进行。

    【讨论】:

      猜你喜欢
      • 2019-10-10
      • 2021-01-11
      • 2019-07-10
      • 2021-05-14
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      • 2018-02-24
      • 2018-03-09
      相关资源
      最近更新 更多