nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.61k stars 2.36k forks source link

Build fails on vercel with its build cache. Build succeeds on redeploy without build cache #8294

Closed tpinne closed 2 years ago

tpinne commented 2 years ago

Current Behavior

If I push a new commit vercel deploys my application automatically including the vercel build cache and the build fails by not finding a local (nx) library (see failure log below). If I do a redeploy without the build cache the deployment works fine.

Expected Behavior

A functioning build everytime even with the vercel build cache.

Steps to Reproduce

Not able to provide a mini-repo or something. It's the app scraping.

workspace.json

{
  "version": 2,
  "projects": {
    "content": "libs/content",
    "db": "libs/db",
    "prisma-client": "libs/prisma-client",
    "scraping": "apps/scraping",
    "scraping-e2e": "apps/scraping-e2e",
    "supabase": "libs/supabase",
    "website": "apps/website",
    "website-e2e": "apps/website-e2e"
  }
}

project.json

The "implicitDependencies": ["prisma-client"], was a try to solve the problem.

{
  "root": "apps/scraping",
  "sourceRoot": "apps/scraping",
  "projectType": "application",
  "implicitDependencies": ["prisma-client"],
  "targets": {
    "build": {
      "executor": "@nrwl/next:build",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "root": "apps/scraping",
        "outputPath": "dist/apps/scraping"
      },
      "configurations": {
        "production": {}
      }
    },
    "serve": {
      "executor": "@nrwl/next:server",
      "options": {
        "buildTarget": "scraping:build",
        "dev": true
      },
      "configurations": {
        "production": {
          "buildTarget": "scraping:build:production",
          "dev": false
        }
      }
    },
    "export": {
      "executor": "@nrwl/next:export",
      "options": {
        "buildTarget": "scraping:build:production"
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/apps/scraping"],
      "options": {
        "jestConfig": "apps/scraping/jest.config.js",
        "passWithNoTests": true
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/scraping/**/*.{ts,tsx,js,jsx}"]
      }
    }
  },
  "tags": []
}

Failure Logs

Cloning github.com/tpinne/bcup (Branch: main, Commit: e6959ee)
--
14:25:23.584 | Cloning completed: 1.589s
14:25:23.667 | Analyzing source code...
14:25:24.660 | Installing build runtime...
14:25:27.563 | Build runtime installed: 2.903s
14:25:29.855 | Looking up build cache...
14:25:37.589 | Build cache downloaded [142.99 MB]: 7291.208ms
14:25:38.473 | Installing dependencies...
14:25:38.785 | yarn install v1.22.17
14:25:38.885 | [1/4] Resolving packages...
14:25:39.722 | success Already up-to-date.
14:25:39.728 | Done in 0.95s.
14:25:39.743 | Detected Next.js version: 12.0.7
14:25:40.036 | Running "npx nx build scraping --prod"
14:25:41.181 |  
14:25:41.182 | > nx run scraping:build:production
14:25:42.548 | withNx() plugin: Detected Vercel build environment, applying "experimental-serverless-trace" target
14:25:42.551 | warn  - The `target` config is deprecated and will be removed in a future version.
14:25:42.551 | See more info here https://nextjs.org/docs/messages/deprecated-target-config
14:25:42.618 | info  - Checking validity of types...
14:25:46.215 | Failed to compile.
14:25:46.215 |  
14:25:46.215 | ./pages/api/parseLeague.ts:1:70
14:25:46.215 | Type error: Cannot find module '@bcup/prisma-client' or its corresponding type declarations.
14:25:46.216 |  
14:25:46.216 | > 1 \| import { BillardAreaLeague, BillardAreaTeam, ScrapeStatusEnum } from '@bcup/prisma-client';
14:25:46.216 | \|                                                                      ^
14:25:46.216 | 2 \| import cheerio from 'cheerio';
14:25:46.217 | 3 \| import { Dictionary } from 'lodash';
14:25:46.217 | 4 \| import type { NextApiRequest, NextApiResponse } from 'next';
14:25:46.230 |  
14:25:46.230 | ———————————————————————————————————————————————
14:25:46.230 |  
14:25:46.231 | >  NX   ERROR  Running target "scraping:build" failed
14:25:46.231 |  
14:25:46.231 | Failed tasks:
14:25:46.231 |  
14:25:46.231 | - scraping:build:production
14:25:46.231 |  
14:25:46.232 | Hint: run the command with --verbose for more details.
14:25:46.232 |  
14:25:46.246 | Error: Command "npx nx build scraping --prod" exited with 1

Succeeding log without the vercel build cache

Cloning github.com/tpinne/bcup (Branch: main, Commit: e6959ee)
--
14:26:17.076 | Cloning completed: 1.381s
14:26:17.141 | Analyzing source code...
14:26:17.727 | Installing build runtime...
14:26:20.374 | Build runtime installed: 2.647s
14:26:22.684 | No Build Cache available
14:26:23.406 | Installing dependencies...
14:26:23.649 | yarn install v1.22.17
14:26:23.732 | [1/4] Resolving packages...
14:26:24.263 | [2/4] Fetching packages...
14:26:53.792 | [3/4] Linking dependencies...
14:26:53.795 | warning "@nrwl/next > @babel/plugin-proposal-decorators@7.16.5" has unmet peer dependency "@babel/core@^7.0.0-0".
14:26:53.795 | warning "@nrwl/next > url-loader@4.1.1" has unmet peer dependency "webpack@^4.0.0 \|\| ^5.0.0".
14:26:53.795 | warning "@nrwl/next > @babel/plugin-proposal-decorators > @babel/helper-create-class-features-plugin@7.16.5" has unmet peer dependency "@babel/core@^7.0.0".
14:26:53.795 | warning "@nrwl/next > @babel/plugin-proposal-decorators > @babel/plugin-syntax-decorators@7.16.5" has unmet peer dependency "@babel/core@^7.0.0-0".
14:26:53.796 | warning "@nrwl/next > @nrwl/cypress > @cypress/webpack-preprocessor@5.10.0" has unmet peer dependency "@babel/core@^7.0.1".
14:26:53.796 | warning "@nrwl/next > @nrwl/cypress > @cypress/webpack-preprocessor@5.10.0" has unmet peer dependency "@babel/preset-env@^7.0.0".
14:26:53.796 | warning "@nrwl/next > @nrwl/cypress > @cypress/webpack-preprocessor@5.10.0" has unmet peer dependency "babel-loader@^8.0.2".
14:26:53.796 | warning "@nrwl/next > @nrwl/cypress > @cypress/webpack-preprocessor@5.10.0" has unmet peer dependency "webpack@^4 \|\| ^5".
14:26:53.804 | warning "babel-jest > babel-preset-jest@27.4.0" has unmet peer dependency "@babel/core@^7.0.0".
14:26:53.808 | warning " > bootstrap@4.6.1" has unmet peer dependency "jquery@1.9.1 - 3".
14:26:53.808 | warning " > bootstrap@4.6.1" has unmet peer dependency "popper.js@^1.16.1".
14:26:53.808 | warning "next > styled-jsx > @babel/plugin-syntax-jsx@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0".
14:26:53.810 | warning " > babel-jest@27.2.3" has unmet peer dependency "@babel/core@^7.8.0".
14:26:53.810 | warning " > eslint-plugin-jsx-a11y@6.4.1" has incorrect peer dependency "eslint@^3 \|\| ^4 \|\| ^5 \|\| ^6 \|\| ^7".
14:26:53.810 | warning " > eslint-plugin-react@7.26.1" has incorrect peer dependency "eslint@^3 \|\| ^4 \|\| ^5 \|\| ^6 \|\| ^7".
14:26:53.811 | warning " > eslint-plugin-react-hooks@4.2.0" has incorrect peer dependency "eslint@^3.0.0 \|\| ^4.0.0 \|\| ^5.0.0 \|\| ^6.0.0 \|\| ^7.0.0".
14:27:22.001 | [4/4] Building fresh packages...
14:27:35.498 | $ prisma generate \|\| true
14:27:35.938 | Environment variables loaded from .env
14:27:36.750 | Prisma schema loaded from libs/prisma-client/prisma/schema.prisma
14:27:38.181 |  
14:27:38.181 | ✔ Generated Prisma Client (3.6.0 \| library) to ./libs/prisma-client/src in 316ms
14:27:38.181 | You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
14:27:38.181 | ```
14:27:38.181 | import { PrismaClient } from './libs/prisma-client/src'
14:27:38.181 | const prisma = new PrismaClient()
14:27:38.181 | ```
14:27:38.255 | Done in 74.61s.
14:27:38.295 | Detected Next.js version: 12.0.7
14:27:38.504 | Running "npx nx build scraping --prod"
14:27:39.895 |  
14:27:39.895 | > nx run scraping:build:production
14:27:40.959 | withNx() plugin: Detected Vercel build environment, applying "experimental-serverless-trace" target
14:27:40.960 | warn  - The `target` config is deprecated and will be removed in a future version.
14:27:40.961 | See more info here https://nextjs.org/docs/messages/deprecated-target-config
14:27:40.984 | Attention: Next.js now collects completely anonymous telemetry regarding usage.
14:27:40.984 | This information is used to shape Next.js' roadmap and prioritize features.
14:27:40.985 | You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
14:27:40.985 | https://nextjs.org/telemetry
14:27:40.985 |  
14:27:41.026 | info  - Checking validity of types...
14:27:44.575 | info  - Creating an optimized production build...
14:27:58.977 | info  - Compiled successfully
14:27:58.977 | info  - Collecting page data...
14:28:01.279 | info  - Generating static pages (0/3)
14:28:01.304 | info  - Generating static pages (3/3)
14:28:01.311 | info  - Finalizing page optimization...
14:28:01.314 |  
14:28:01.331 | Page                                       Size     First Load JS
14:28:01.331 | ┌ ○ /                                      280 B          71.8 kB
14:28:01.331 | ├   /_app                                  0 B            71.5 kB
14:28:01.331 | ├ ○ /404                                   193 B          71.7 kB
14:28:01.332 | ├ λ /api/parseLeague                       0 B            71.5 kB
14:28:01.332 | ├ λ /api/parseMatchDays                    0 B            71.5 kB
14:28:01.332 | └ λ /api/scheduleSeason                    0 B            71.5 kB
14:28:01.332 | + First Load JS shared by all              71.5 kB
14:28:01.332 | ├ chunks/framework-c4190dd27fdc6a34.js   42 kB
14:28:01.332 | ├ chunks/main-770e124cf078f84c.js        28.2 kB
14:28:01.332 | ├ chunks/pages/_app-cc9f360f078af23b.js  588 B
14:28:01.332 | └ chunks/webpack-45f9f9587e6c08e1.js     729 B
14:28:01.332 |  
14:28:01.332 | λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
14:28:01.332 | ○  (Static)  automatically rendered as static HTML (uses no initial props)
14:28:01.333 |  
14:28:01.585 |  
14:28:01.586 | ———————————————————————————————————————————————
14:28:01.586 |  
14:28:01.586 | >  NX   SUCCESS  Running target "build" succeeded
14:28:01.586 |  
14:28:01.586 |  
14:28:01.927 | Traced Next.js server files in: 309.825ms
14:28:10.251 | Created all serverless functions in: 8.323s
14:28:10.412 | Uploading build outputs...
14:28:11.497 | Deploying build outputs...
14:28:17.025 | Build completed. Populating build cache...
14:28:44.243 | Uploading build cache [142.91 MB]...
14:28:49.216 | Build cache uploaded: 4.957s
14:28:49.239 | Done with "package.json"

Environment

$ nx report

>  NX  Report complete - copy this into the issue template

  Node : 14.18.1
  OS   : darwin x64
  yarn : 1.22.5

  nx : 13.3.6
  @nrwl/angular : undefined
  @nrwl/cli : 13.3.6
  @nrwl/cypress : 13.3.6
  @nrwl/devkit : 13.3.6
  @nrwl/eslint-plugin-nx : 13.3.6
  @nrwl/express : undefined
  @nrwl/jest : 13.3.6
  @nrwl/linter : 13.3.6
  @nrwl/nest : undefined
  @nrwl/next : 13.3.6
  @nrwl/node : 13.3.6
  @nrwl/nx-cloud : undefined
  @nrwl/react : 13.3.6
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.3.6
  @nrwl/web : 13.3.6
  @nrwl/workspace : 13.3.6
  @nrwl/storybook : 13.3.6
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 6.6.7
  ---------------------------------------
  Community plugins:
kirjai commented 2 years ago

thanks for opening the issue @tpinne! unfortunately i'm not having much luck recreating the issue. It'd be helpful if you could isolate it in a repro repo that you could provide, but i appreciate that it's not always easy to do. looking at the provided commands and logs, nothing looks out of the ordinary

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

n3oney commented 2 years ago

I seem to have the same issue. The project is very minimal (about 5 files), deploying it on Vercel produces this: image After i try redeploying without checking the option to use Vercel's cache, it deploys correctly.

vlakyi commented 2 years ago

I have the same issue. But sometimes I receive this issue as well: image

pablodavila95 commented 2 years ago

We are getting the same issue with v12.1.6. Are there any updates on this?

vlakyi commented 2 years ago

Hey, I don’t have any updates on this. Since this issue appeared I have disabled the build cache on vercel and nx.

On 21 Jul 2022, at 18:21, Pablo Dávila @.***> wrote:

We are getting the same issue with v12.1.6. Are there any updates on this?

— Reply to this email directly, view it on GitHub https://github.com/nrwl/nx/issues/8294#issuecomment-1191691305, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANCTKB2OKJBYFZTS54LR2K3VVF2H7ANCNFSM5KVNMSEA. You are receiving this because you commented.

mxa0079 commented 1 year ago

Hello,

This issue is still active on our repo. We have followed the documentation without success. We can get a successful build but only after a redeploy skipping cache.

Naser2 commented 1 year ago

Same issue here

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.