Turborepo cache miss in Vercel Deployment when I use Environment Variable in Next.js Project

250 views Asked by At

I'm trying to use local build cache on Vercel Deployment process. When I build my Next.js project on my local env, turborepo cache my project very well. But when I build on Vercel Deploy, my Next.js Project always have cache miss problem. How can I use my local build cache on Vercel Deploy?

I tried change turbo.json file.

turbo.json

{
  "$schema": "https://turbo.build/schema.json",
  "globalDependencies": [".env"],
  "globalDotEnv": [".env"],
  "globalEnv": ["DB_URL"],
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**"],
      "env": ["DB_URL"]
    },
    "lint": {},
    "dev": {
      "cache": false,
      "persistent": true
    }
  }
}

Root package.json

{
  "private": true,
  "scripts": {
    "build": "dotenv -- turbo run build",
    "dev": "turbo run dev",
    "lint": "turbo run lint",
    "format": "prettier --write \"**/*.{ts,tsx,md}\""
  },
  "devDependencies": {
    "eslint": "^8.48.0",
    "prettier": "^3.0.3",
    "tsconfig": "workspace:*",
    "turbo": "^1.10.16",
    "dotenv-cli": "^7.3.0"
  },
  "packageManager": "[email protected]",
  "name": "my-monorepo"
}

Next.js Project package.json

{
  "name": "my-nextjs-project",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "^14.0.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ui": "workspace:*"
  },
  "devDependencies": {
    "@next/eslint-plugin-next": "^14.0.2",
    "@types/node": "^20.9.0",
    "@types/react": "^18.2.37",
    "@types/react-dom": "^18.2.15",
    "autoprefixer": "^10.4.16",
    "eslint-config-custom": "workspace:*",
    "postcss": "^8.4.31",
    "tailwindcss": "^3.3.5",
    "tsconfig": "workspace:*",
    "tsx": "^4.1.1",
    "typescript": "^5.2.2"
  }
}

package manager : pnpm v8.6.10

0

There are 0 answers