简体   繁体   中英

TS2688: Cannot find type definition file for 'node' with @types/node installed

I'm having a difficult time building a TypeScript application on Heroku.

My dependencies list includes a type definition for all of the packages I'm using:

"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"
  },

However, when building on Heroku, I get:

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

and more. My tsconfig.json sets the typeRoots as './node_modules/@types' and I get a successful build locally.

Why can't Heroku find these types?

Apparently Heroku wasn't picking up changes to my package.json file or had cached some portion of the build process that was excluding @type definitions that I had moved from devDependencies to dependencies.

I cleared the build cache as such:

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

and everything works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM