Vite 部署到 vercel,但客户端和服务器目录不起作用

问题描述 投票:0回答:1

我正在尝试部署到 vercel,但我从未使用过后端,这次我有 2 个目录:服务器和客户端。我尝试使用客户端目录进行部署,但很快发现我的后端明显没有运行,因为运行命令不包含它。

经过一些研究,我发现在根目录中创建一个脚本来运行客户端和服务器是可能的,并且在将所有后端依赖项导入根package.json并同时设置后,我遇到了以下部署问题:

sh: tsc: command not found
Error: Command "npm run build" exited with 127

我的fs看起来像这样:

root:
    -client
    -server
    .gitignore
    .env
    .package.json
    .node_modules
    .package-log.json
    .npm-debug.log

这是我的根package.json:

{
  "name": "finance",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "server": "nodemon --quiet server",
    "build":"cd ./client && npm run build",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "repository": {
    "type": "git",

  },
  "keywords": [],
  "author": "",
  "license": "ISC",


  "dependencies": {
    "bcrypt": "^5.1.0",
    "body-parser": "^1.20.2",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "helmet": "^6.0.1",
    "jsonwebtoken": "^9.0.0",
    "mongoose": "^7.3.1",
    "morgan": "^1.10.0",
    "react-cookie": "^4.1.1",
    "universal-cookie": "^4.0.4"
  },
  "devDependencies": {
    "concurrently": "^8.2.0",
    "nodemon": "^3.0.1",
    "@faker-js/faker": "^8.0.2"
  }
}

这也是我的客户端 package.json:

{
  "name": "client",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "tsc && vite build",
    "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@mui/icons-material": "^5.11.11",
    "@mui/material": "^5.11.11",
    "@mui/x-data-grid": "^6.0.0",
    "@mui/x-date-pickers": "^6.9.1",
    "@nivo/pie": "^0.83.0",
    "@reduxjs/toolkit": "^1.9.3",
    "dayjs": "^1.11.8",
    "formik": "^2.4.2",
    "react": "^18.2.0",
    "react-cookie": "^4.1.1",
    "react-dom": "^18.2.0",
    "react-hot-toast": "^2.4.1",
    "react-redux": "^8.0.5",
    "react-router-dom": "^6.8.2",
    "recharts": "^2.7.2",
    "regression": "^2.0.1",
    "universal-cookie": "^4.0.4",
    "yup": "^1.2.0"
  },
  "devDependencies": {
    "@types/node": "^18.16.18",
    "@types/react": "^18.0.27",
    "@types/react-dom": "^18.0.11",
    "@types/regression": "^2.0.2",
    "@vitejs/plugin-react": "^3.1.0",
    "eslint": "^8.35.0",
    "eslint-config-react-app": "^7.0.1",
    "prettier": "^2.8.8",
    "typescript": "^4.9.5",
    "vite": "^4.4.4"
  }
}

我尝试通过全局安装打字稿(这不起作用):

npm install typescript -g

但是我包含的脚本不应该解决这个问题吗,因为构建是在客户端文件夹中进行的?

"build":"cd ./client && npm run build",

我不适合这里,任何帮助都会很棒!

vite vercel tsc
1个回答
0
投票

您是否已经解决了 vercel 上的后端和前端问题?

© www.soinside.com 2019 - 2024. All rights reserved.