reactjs - React.js Vercel 部署错误消息 |错误: No Output Directory named "build" found after the Build completed

标签 reactjs typescript heroku vercel

我在发布我在 Vercel 中制作的 React.js typescript 项目时遇到了这样的错误。我还没找到解决办法。

Vercel publishing error as follows

我的Package Json文件是这样的;

{
  "name": "jodee-frontend",
  "version": "1.0.0",
  "engines": {
    "node": "16.x",
    "npm": "8.x"
  },
  "private": true,
  "type": "module",
  "dependencies": {
    "@hookform/resolvers": "^2.9.10",
    "@reduxjs/toolkit": "^1.9.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.18.10",
    "@types/react-dom": "^18.0.10",
    "eslint-plugin-simple-import-sort": "^8.0.0",
    "jwt-decode": "^3.1.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.33.1",
    "react-icons": "^4.7.1",
    "react-redux": "^8.0.5",
    "react-router-dom": "^6.6.0",
    "react-scripts": "5.0.1",
    "sass": "^1.57.1",
    "typescript": "*",
    "web-vitals": "^2.1.4",
    "yup": "^0.32.11"
  },
  "scripts": {
    "dev": "vite --port 3000",
    "build": "vite build",
    "preview": "vite preview",
    "type-check": "tsc",
    "type-check:no-artifact": "tsc --skipLibCheck --noEmit",
    "lint:fix": "eslint ./src --ext .jsx,.js,.ts,.tsx --fix --max-warnings=0 --ignore-path ./.gitignore",
    "lint:format": "prettier  --loglevel warn --write \"./**/*.{js,jsx,ts,tsx,css,md,json}\" ",
    "lint": "yarn lint:format && yarn lint:fix ",
    "release": "standard-version",
    "prepare": "husky install"
  },
  "lint-staged": {
    "./src/**/*.{ts,tsx}": [
      "eslint --max-warnings=0",
      "prettier --write --ignore-unknown"
    ]
  },
  "devDependencies": {
    "@commitlint/cli": "^17.3.0",
    "@commitlint/config-conventional": "^17.3.0",
    "@types/react": "^18.0.26",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.31.0",
    "@vitejs/plugin-react": "^3.0.0",
    "autoprefixer": "^10.4.13",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-standard-with-typescript": "^24.0.0",
    "eslint-plugin-import": "^2.25.2",
    "eslint-plugin-jsx-a11y": "^6.6.1",
    "eslint-plugin-n": "^15.0.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.31.11",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-simple-import-sort": "^8.0.0",
    "husky": "^8.0.0",
    "lint-staged": "^13.0.3",
    "postcss": "^8.4.20",
    "prettier": "^2.8.1",
    "standard-version": "^9.5.0",
    "tailwindcss": "^3.2.4",
    "typescript": "^4.6.4",
    "vite": "^4.0.0"
  }
}

我的vite.config.js文件如下;

import react from "@vitejs/plugin-react"
import * as path from "path"
import { defineConfig } from "vite"

// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
  return {
    plugins: [react()],
    resolve: {
      alias: [{ find: "@", replacement: path.resolve(__dirname, "./src") }],
    },
    optimizeDeps: {
      esbuildOptions: {
        // Node.js global to browser globalThis
        define: {
          global: "globalThis",
        },
      },
    },
  }
})

我的 tsconfig.json 文件是这样的;

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "rootDir": "./src",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

我正在等待项目在 vercel 中发布,但我不断遇到此错误。我什至在 Heroku 上遇到了类似的错误。

最佳答案

我也遇到了类似的问题。 要解决此问题,请转到您的项目设置 => 常规并覆盖以下命令:

构建命令: yarn 构建

输出目录:dist

开发命令:yarn dev

PS:用你的包管理器替换yarn。 This is an example of my Project settings. Goodluck!

关于reactjs - React.js Vercel 部署错误消息 |错误: No Output Directory named "build" found after the Build completed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75025474/

相关文章:

reactjs - 开 Jest 如何检查 spy 函数中被调用的 spy 函数?

javascript - 将时刻导入 TypeScript 项目

ruby-on-rails - Heroku:如何在 "git pull"之后到 'git push -f'

ruby-on-rails - 迁移到 postgresql 时无法创建数据库

javascript - 在reactjs中添加两个数字

javascript - redux-saga:函数被调用两次

typescript - 带有 Aurelia 和 typescript 的 dhtmlxscheduler

javascript - 如何在 javascript/typescript 中使用新的 Gremlin 3.x 语法编写旧查询

python - 如何使用 Flask 在 Heroku 中显示标准输出日志?

node.js - 尝试在 linux 上运行 npm run build 时,NPM 给出 ELILIFECYCLE 错误