It failed when building a next application with config `output:standalone`.
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
- Clone the repo.
pnpm inx 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
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
No response
Same here
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
Just delete the scripts in package.json and only keep scripts in project.json
On Fri, 8 Nov 2024 at 1:22 PM Muhammad Alfian Rasyidin < @.***> wrote:
The issue persists in the latest Nx version (v20.0.11). Is there any additional action planned to address this? @jaysoo https://github.com/jaysoo @ndcunningham https://github.com/ndcunningham
Thanks!
Error: File exists (os error 17) at @.***/node_modules/nx/src/tasks-runner/cache.js:317:17
— Reply to this email directly, view it on GitHub https://github.com/nrwl/nx/issues/27724#issuecomment-2464214065, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC5TWOAZONARH6NVIGBKFGTZ7R7G3AVCNFSM6AAAAABNOPB2H6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRUGIYTIMBWGU . You are receiving this because you authored the thread.Message ID: @.***>
Big help, thanks! @ibufu
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?
The root cause is that nx run the build script twice. You can use nx show to figure out it.
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)
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.
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
--skipNxCache worked around the issue for me too
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:
pnpx create-nx-workspace nx-21using [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
- Add
output: "standalone"to next.config.js - 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 https://github.com/nrwl/nx/issues/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
Same here, I have another workaround option:
Add this to the package.json or project.json
{
...
"targets": {
"build": {
"cache": false
}
...
any progress?
Same issue here :(
I solved this by using the target output {projectRoot}/.next/standalone instead of {projectRoot}/.next/standalone/**/*
Any official solution, any update?
I'm also experiencing the same on my side
ditto here, also experiencing this
still an issue in nx 22
I'm still not sure why this is happening, yet I found the cleanest workaround for my needs.
The inferred plugin outputs paths are
{workspaceRoot}/apps/web/.next/!(cache)/**/*
{workspaceRoot}/apps/web/.next/!(cache)
I changed them by configuring the target with this output path:
{
"targets": {
"build": {
"outputs": [
"{projectRoot}/.next"
]
}
}
}
and it works.
I tried ignoring the .next/cache dir following the same pattern as the default imports in the nx.json:
{
"targets": {
"build": {
"outputs": [
"{projectRoot}/.next",
"!{projectRoot}/.next/cache"
]
}
}
}
but had no luck.