Heroku出现问题:sh: 1: tsc: 找不到

4
这是我的脚本。
     {
  "name": "fullstack-apollo-express-boilerplate-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "tsc": "./node_modules/typescript/bin/tsc",
    "build": "rimraf ./build && tsc",
    "dev": "nodemon",
    "start": "npm run build && node build/index.js",
    "codegen": "graphql-codegen --config ./codegen.yml",
    "lint": "eslint . --ext .ts",
    "lint-and-fix": "eslint . --ext .ts --fix",
    "prettier-format": "prettier --config .prettierrc src/**/*.ts --write"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@graphql-codegen/cli": "^2.3.0",
    "@graphql-codegen/typescript": "^2.4.1",
    "@graphql-codegen/typescript-resolvers": "^2.4.2",
    "@shopify/eslint-plugin": "^41.0.1",
    "@types/bcryptjs": "^2.4.2",
    "@types/cookie-parser": "^1.4.2",
    "@types/mongoose-lean-virtuals": "^0.5.2",
    "@types/nodemailer": "^6.4.4",
    "@types/uuid": "^8.3.3",
    "@typescript-eslint/eslint-plugin": "^5.5.0",
    "@typescript-eslint/parser": "^5.5.0",
    "eslint": "^8.4.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-prettier": "^4.0.0",
    "nodemon": "^2.0.15",
    "prettier": "^2.5.1",
    "ts-node": "^10.4.0",
    "typescript": "^4.5.2"
  },
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^16.11.11",
    "apollo-server-core": "^3.5.0",
    "apollo-server-express": "^3.5.0",
    "bcryptjs": "^2.4.3",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "crypto-random-string": "3.3.1",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "express-openid-connect": "^2.5.1",
    "graphql": "^16.0.1",
    "graphql-fields-list": "^2.2.4",
    "graphql-parse-resolve-info": "^4.12.0",
    "graphql-voyager": "^1.0.0-rc.31",
    "i": "^0.3.7",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.29.1",
    "mongoose": "^6.0.14",
    "mongoose-lean-virtuals": "^0.9.0",
    "nodemailer": "^6.7.2",
    "rimraf": "^3.0.2"
  }
}

当我部署时,出现错误。
2022-01-14T08:20:20.950719+00:00 app[web.1]: sh: 1: tsc: not found
2022-01-14T08:20:20.956238+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-01-14T08:20:20.956684+00:00 app[web.1]: npm ERR! syscall spawn
2022-01-14T08:20:20.956866+00:00 app[web.1]: npm ERR! file sh
2022-01-14T08:20:20.956950+00:00 app[web.1]: npm ERR! errno ENOENT
2022-01-14T08:20:20.961092+00:00 app[web.1]: npm ERR! fullstack-apollo-express-boilerplate-project@1.0.0 build: `rimraf ./build && tsc`
2022-01-14T08:20:20.961191+00:00 app[web.1]: npm ERR! spawn ENOENT
2022-01-14T08:20:20.961291+00:00 app[web.1]: npm ERR!
2022-01-14T08:20:20.961337+00:00 app[web.1]: npm ERR! Failed at the fullstack-apollo-express-boilerplate-project@1.0.0 build script.
2022-01-14T08:20:20.961377+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    2022-01-14T08:20:20.961191+00:00 app[web.1]: npm ERR! spawn ENOENT
    2022-01-14T08:20:20.961291+00:00 app[web.1]: npm ERR!
    2022-01-14T08:20:20.961337+00:00 app[web.1]: npm ERR! Failed at the fullstack-apollo-express-boilerplate-project@1.0.0 build script.
    2022-01-14T08:20:20.961377+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我无法弄清楚原因,一切对我来说都运行良好。

1个回答

10
如果您没有Procfile,Heroku将按照Web进程运行start脚本。
您的start脚本运行您的build脚本,而您的build脚本使用tsc编译您的应用程序。
"build": "rimraf ./build && tsc",
"start": "npm run build && node build/index.js",
//        ^^^^^^^^^^^^^

这会导致 Heroku 在每次 dyno 启动时尝试编译您的应用程序,由于 typescript 是(正确地)一个 devDependency ,因此tsc在运行时不可用。
start 脚本不再调用build脚本并进行修改,这是没有必要的:您的应用程序只需要编译一次。
"build": "rimraf ./build && tsc",
"start": "node build/index.js",

Heroku会在部署时自动运行你的build脚本,现在它不会在运行时重新编译。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接