![](/img/trans.png)
[英]Heroku shows Application Error for NodeJS app even though it runs perfectly in my local machine
[英]While deploying a NodeJs app to heroku, I started getting tsc compilation error even though tsc works fine in my machine
我已經使用 heroku 有一段時間了,直到我創建了一個新實體 model 和 controller 之前我沒有任何錯誤。 提交這些更改后,我嘗試部署到 heroku。 我收到此錯誤消息。
...
-----> 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
...
在這個日志之后,我再次檢查了我的代碼,並沒有發現任何錯誤。 然后,我嘗試在本地運行 tsc 命令。 它工作正常並生成了 dist 文件。 我找不到 tsc 在 heroku 上給出錯誤的任何原因。
這些是 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"
}
這里是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
}
}
任何想法都會有所幫助。
編輯:似乎導入行引起了問題。 我import {Order} from "../../db/Order";
import {Order} from "../../db/order";
它沒有給出錯誤。 它在本地使用 ts-node 和 tsc 工作正常,但不能在 heroku 使用 tsc。
似乎導入行引起了問題。 我import {Order} from "../../db/Order";
import {Order} from "../../db/order";
它沒有給出錯誤。 它在本地使用 ts-node 和 tsc 工作正常,但不能在 heroku 使用 tsc。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.