Skip to content

It failed when building a next application with config output:standalone. #27724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
ibufu opened this issue Sep 1, 2024 · 11 comments
Open
1 of 4 tasks
Assignees
Labels
scope: nextjs Issues related to NextJS support for Nx type: bug

Comments

@ibufu
Copy link

ibufu commented Sep 1, 2024

Current Behavior

After integrating to an existed pnpm monorepo, it failed when building a next application with config output:standalone.

Expected Behavior

nx build next-app --verbose
Error: File exists (os error 17)
    at /nx-next-standalone/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/cache.js:145:17

GitHub Repo

https://github.com/ibufu/nx-next-standalone

Steps to Reproduce

  1. Clone the repo.
  2. pnpm i
  3. nx build next-app

Nx Report

Node           : 18.20.4
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.9.0

nx (global)  : 19.6.4
nx           : 19.6.4
@nx/eslint   : 19.6.4
@nx/next     : 19.6.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/next/plugin

Failure Logs

Error: File exists (os error 17)
    at /nx-next-standalone/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/cache.js:145:17

Package Manager Version

[email protected]

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@ibufu ibufu added the type: bug label Sep 1, 2024
@jaysoo jaysoo added the scope: nextjs Issues related to NextJS support for Nx label Sep 25, 2024
@jackhefoong
Copy link

Same here

@malfianrasyidin
Copy link

The issue persists in the latest Nx version (v20.0.11).
Is there any additional action planned to address this?
@jaysoo @ndcunningham

Thanks!

Error: File exists (os error 17)
    at /node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/cache.js:317:17

@ibufu
Copy link
Author

ibufu commented Nov 8, 2024 via email

@jackhefoong
Copy link

Big help, thanks! @ibufu

@counterbeing
Copy link

counterbeing commented Nov 8, 2024

I'm getting the same error.

I'm trying to understand how not using package.json scripts would help? I'm also trying to understand how to update my project.json to actually build correctly.I went with a package.json script for this particular library because it has a couple of steps:

    "bundle": "tsx ./src/bundle.ts",
    "build": "rm -rf ./dist && tsc -p tsconfig.lib.json && pnpm run bundle"
  }

How would i convert that into a project.json syntax, and how would that fix the problem? Or would it?

@ibufu
Copy link
Author

ibufu commented Nov 8, 2024

The root cause is that nx run the build script twice. You can use nx show to figure out it.

@counterbeing
Copy link

I've moved to this structure in my project.json for this package:

{
  "name": "workflow-bundler",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "packages/workflow-bundler/src",
  "projectType": "library",
  "tags": [],
  "targets": {
    "build": {
      "executor": "nx:run-commands",
      "options": {
        "command": "say 'hello';rm -rf ./dist && tsc -p tsconfig.lib.json && tsx ./src/bundle.ts"
      }
    }
  }
}

That say 'hello' is just there so i can hear if it happens to run twice. It's now only running once. I've entirely removed the scripts section from my package.json. However i'm still getting:

    at /Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:84:24
    at _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:397:26)
    at _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:406:26)
    at async _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:406:20)
    at async _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:406:20)
    at async _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:406:20)
    at async _try (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/cache.js:406:20)
    at async Promise.all (index 0)
    at async TaskOrchestrator.postRunSteps (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/task-orchestrator.js:345:13)
    at async TaskOrchestrator.applyFromCacheOrRunTask (/Users/cory.logan/Code/my-project/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_t_rpge6wb46b7rpyw5yhycwpxahy/node_modules/nx/src/tasks-runner/task-orchestrator.js:295:9)

@CristianHG2
Copy link

I'm also experiencing this issue. On my end, there seems to be some conflict with the cache entries for Nx. It seems it is trying to write to the cache, but the key already exists, which causes this issue.

Running the command with --skipNxCache worked for me.

@caioquirino
Copy link

For my setup, the issue was also gone after adding --skipNxCache (which is not the ideal solution). Tested with the latest NX version: 20.7.1

@OrenSayag
Copy link

--skipNxCache worked around the issue for me too

@drewandre
Copy link

drewandre commented May 6, 2025

This is still broken in the latest NV v21.0.0. It's unfortunate because we have to disable standalone output when running outside of CI, which produces a different build, so it's difficult to run our true production compiled next.js app locally.

Steps to reproduce below:

  1. pnpx create-nx-workspace nx-21 using [email protected] with the following options:
  • "React" for stack
  • "Next.js" for framework
  • App Router: yes
  • src/ directory: yes
  • Unit test runner: Jest
  • E2E test runner: Playwright
  • Stylesheet: tailwind
  • Eslint: yes
  • Prettier: yes
  1. Add output: "standalone" to next.config.js
  2. Run inferred next.js build command - see output error

Besides react and next.js, I don't think the choices above make a difference - I haven't tried with a different test runner or style system for example. But just a basic [email protected] standalone next.js build fails pretty easily.

A lot of next.js builds are dockerized (to avoid high vercel pricing), which is why standalone is so important. Our team isn't completely blocked because we just disable nx caching in our CI pipeline. And yes, --skipNxCache does fix the issue, but obviously not a long term solution.

ianldgs for visibility, since we had a brief discussion on #30733 earlier.

nx report

Node : 20.19.0 OS : darwin-arm64 Native Target : aarch64-macos pnpm : 10.8.0

nx : 21.0.0
@nx/js : 21.0.0
@nx/jest : 21.0.0
@nx/eslint : 21.0.0
@nx/workspace : 21.0.0
@nx/devkit : 21.0.0
@nx/eslint-plugin : 21.0.0
@nx/module-federation : 21.0.0
@nx/next : 21.0.0
@nx/playwright : 21.0.0
@nx/react : 21.0.0
@nx/web : 21.0.0
@nx/webpack : 21.0.0
typescript : 5.7.3

Registered Plugins:
@nx/js/typescript
@nx/next/plugin
@nx/playwright/plugin
@nx/eslint/plugin
@nx/jest/plugin

Cache Usage: 0.00 B / 92.64 GB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: nextjs Issues related to NextJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

10 participants