简体   繁体   English

Node express + typescript 部署在 Vercel 上未构建

[英]Node express + typescript deployment on vercel not building

I have upload my project with node using express + typescript. This app generates a folder dist for building but when vercel deploy my app it doesn't run the command build so what I had to do for deploy my app is build locally and upload this dist folder.我已经使用 express + typescript 上传了我的节点项目。这个应用程序生成一个文件夹dist用于构建但是当 vercel 部署我的应用程序时它不运行命令构建所以我必须做的部署我的应用程序是在本地构建并上传这个dist文件夹。 Here is my vercel.json这是我的 vercel.json

{
    "version": 2,
    "buildCommand": "yarn build",
    "devCommand": "yarn dev",
    "outputDirectory": "dist",
    "builds": [
        {
            "src": "dist/index.js",
            "use": "@vercel/node"
        }
      ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "dist/index.js"
        }
    ]
}

have you provided "build":"tsc" in script tag in package.json?您是否在 package.json 的脚本标签中提供了“build”:“tsc”?

   "build":"tsc",
   "start": "node dist/server.js",

However, I haven't build my express with TS app and deployed it in vercel.但是,我还没有使用 TS app 构建我的 express 并将其部署在 vercel 中。 You have to install typescript only once in vercel in order to run expressTS app without compiling/building it.您只需在 Vercel 中安装一次 typescript 即可运行 expressTS 应用程序而无需编译/构建它。

   vercel.json
        {
          "version": 2,
            "builds": [
              {
                "src": "./server.ts",   // server.ts is in root
                "use": "@vercel/node"
              }
            ],
            "routes": [
              {
                "src": "/.*",
                "dest": "server.ts"
              }
            ]
          }

package.json package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "MERN App",
  "main": "server.ts",
  "scripts": {
    "start": "node server.ts",
    "server": "ts-node ./server.ts",
    "client": "cd ./ && npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "mongoose": "^6.7.2"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.14",
    "concurrently": "^7.5.0",
    "ts-node": "^10.9.1"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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