Search code examples
reactjstypescriptherokuvercel

React.js Vercel Deploy Error Message | Error: No Output Directory named "build" found after the Build completed


I am encountering such an error while publishing the React.js typescript project I have made in Vercel. I haven't been able to find a solution.

Vercel publishing error as follows

My Package Json file is like this;

{
  "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"
  }
}

My vite.config.js file is as follows;

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",
        },
      },
    },
  }
})

My tsconfig.json file is like this;

{
  "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" }]
}

I'm waiting for the project to be published in vercel, but I constantly encountered this error. I even encountered similar errors on Heroku.


Solution

  • I had a similar problem. To fix this go to your Project setting => General and override the following commands:

    Build command: yarn build

    Output directory: dist

    Development command: yarn dev

    PS: Replace yarn with your package manager. This is an example of my Project settings. Goodluck!