nx: Deploying next.js app to vercel or netlify throws error

Current Behavior

Unable to deploy a fresh nx/next. js repo to vercel or netlify

Expected Behavior

Be able to run the build command as described in the docs

Steps to Reproduce

  1. create new nx repo with the default next.js app
  2. deploy to vercel as decribed here
  3. have build fail

Failure Logs

Vercel

09:15:59.771 > NX ERROR Running target “check-in:build” failed
09:15:59.771 Failed tasks:
09:15:59.771
09:15:59.771 - check-in:build:production
09:15:59.789 Error: Command “npx nx build check-in --prod --outputPath=.” exited with 1

Netlify

10:29:49 PM: ──────────────────────────────────────────────────────────────── 10:29:49 PM: "build.command" failed 10:29:49 PM: ──────────────────────────────────────────────────────────────── 10:29:49 PM: ​ 10:29:49 PM: Error message 10:29:49 PM: Command failed with exit code 1: nx build check-in --output-path=. --verbose 10:29:49 PM: ​ 10:29:49 PM: Error location 10:29:49 PM: In Build command from Netlify app: 10:29:49 PM: nx build check-in --output-path=. --verbose

Environment

This happens on netlify and on vercel

Link to repo

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (2 by maintainers)

Most upvoted comments

I dug into this and have confirmed that the issue lies somewhere in the nx-cloud tasks runner, so I have updated the scope and assigned to Victor as I cannot investigate any further.

@simonpeters I have come up with a workaround to unblock deployments until this is resolved:

Go to your nx.json and add a new tasks runner entry within tasksRunnerOptions under your existing one (which will be called “default”), e.g. I have called mine no-cloud:

{
  // ...
  "tasksRunnerOptions": {
    "default": {
      "runner": "@nrwl/nx-cloud",
      "options": {
        "accessToken": "FOOBAR",
        "cacheableOperations": ["build", "test", "lint", "e2e"],
        "canTrackAnalytics": false,
        "showUsageWarnings": true
      }
    },
+   "no-cloud": {
+     "runner": "@nrwl/workspace/src/tasks-runner/default-tasks-runner",
+     "options": {}
+   }
  },
  // ...
}

Then append --runner=no-cloud to your build command that you run on Vercel or Netlify, e.g.

npx nx build your-project --outputPath=. --runner=no-cloud

This works for me locally and on Vercel.

I’m pleased to report that after quite a bit of iteration it seems that my specific cache for my specific projects had ended up in a bad state. Unfortunately I cannot be 100% sure how that happened, but if anybody else finds themselves in this position after changing their Vercel config, I recommend you just create a commit which will bust the cache (i.e. make your project “affected” as far as Nx is concerned) for your particular project and push up to trigger a new build.

Since doing that I have not had any further issues so we don’t need to open a new issue for this.

We have merged an update to the documentation. we no longer advise to use --outputPath=.. please use a custom build output path instead. Refer to the updated documentation for more details.

If you experience any issues with the updated approach, please open a new issue