Home > Software design >  While deploying a NodeJs app to heroku, I started getting tsc compilation error even though tsc work
While deploying a NodeJs app to heroku, I started getting tsc compilation error even though tsc work

Time:08-06

I have been using heroku for a while now and I did not have any error until I created a new entity model and controller. After committing these changes I tried to deploy to heroku. I got this error message.

...
-----> Installing dependencies
       Installing node modules (yarn.lock)
       yarn install v1.22.19
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       [3/4] Linking dependencies...
       [4/4] Building fresh packages...
       $ tsc
       src/user/order/controller.ts(10,21): error TS2307: Cannot find module '../../db/Order' or its corresponding type declarations.
       src/user/order/controller.ts(12,27): error TS2307: Cannot find module '../../db/entity/Order' or its corresponding type declarations.
       src/user/order/controller.ts(110,49): error TS7006: Parameter 'e' implicitly has an 'any' type.
       src/user/order/controller.ts(139,61): error TS7031: Binding element 'recipeId' implicitly has an 'any' type.
       src/user/order/controller.ts(139,71): error TS7031: Binding element 'quantity' implicitly has an 'any' type.
       src/user/order/controller.ts(164,13): error TS2322: Type '[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]' is not assignable to type '{ recipe: { coffeeName: string; usedBrandIngredients: { brandIngredient: string; amount: number; }[]; }; quantity: number; }[]'.
         Type '{}' is missing the following properties from type '{ recipe: { coffeeName: string; usedBrandIngredients: { brandIngredient: string; amount: number; }[]; }; quantity: number; }': recipe, quantity
       src/user/order/model.ts(2,27): error TS2307: Cannot find module '../../db/entity/Order' or its corresponding type declarations.
       error Command failed with exit code 2.
       info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
-----> Build failed
...

After this log, I checked my code again and did not find any error. Then, I tried to run tsc command locally. It worked fine and generated the dist file. I could not find any reason why tsc gives error on heroku.

These are the scripts and dependencies at package.json

  "scripts": {
    "postinstall": "tsc",
    "develop": "nodemon src/services/api.ts",
    "start": "node dist/services/api.js"
  },
  "dependencies": {
    "bcrypt": "^5.0.1",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "express-validator": "^6.12.1",
    "helmet": "^4.6.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.12.14",
    "nodemailer": "^6.7.4"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.0",
    "@types/cors": "^2.8.12",
    "@types/dotenv": "^8.2.0",
    "@types/express": "^4.17.13",
    "@types/express-validator": "^3.0.0",
    "@types/jsonwebtoken": "^8.5.5",
    "@types/mongoose": "^5.11.97",
    "@types/node": "^16.7.12",
    "@types/nodemailer": "^6.4.4",
    "nodemon": "^2.0.12",
    "ts-node": "^10.2.1",
    "typescript": "^4.4.2"
  }

Here is the content of the tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "resolveJsonModule": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/*"
      ]
    }
  },
  "include": [
    "src/**/*"
  ],
  "ts-node": {
    "files": true
  }
}

Any idea would be helpful.

EDIT: It seems that the import line was causing problem. I changed import {Order} from "../../db/Order"; to import {Order} from "../../db/order"; and it did not give error. It was working fine on local with ts-node and tsc, but was not working with the tsc at heroku.

CodePudding user response:

It seems that the import line was causing problem. I changed import {Order} from "../../db/Order"; to import {Order} from "../../db/order"; and it did not give error. It was working fine on local with ts-node and tsc, but was not working with the tsc at heroku.

  • Related