nrwl / nx

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

Nx Generate Fails #20551

Open joshua-auchincloss opened 11 months ago

joshua-auchincloss commented 11 months ago

Current Behavior

NX fails to generate new workspaces.

Command

(base) $ pnpm create create-nx-workspace@latest
.pnpm/store/v3/tmp/dlx-89764             |  +67 +++++++
.pnpm/store/v3/tmp/dlx-89764             | Progress: resolved 67, reused 66, downloaded 1, added 67, done

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · front
✔ Which stack do you want to use? · react
✔ What framework would you like to use? · none
✔ Integrated monorepo, or standalone project? · integrated
✔ Application name · abc
✔ Which bundler would you like to use? · vite
✔ Test runner to use for end to end (E2E) tests · playwright
✔ Default stylesheet format · css
✔ Enable distributed caching to make your CI faster · No

 >  NX   Creating your v17.1.3 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "pnpm install" several times. Please wait.

✔ Installing dependencies with pnpm
✖ Creating your workspace in front

 >  NX   Failed to create a workspace.

   Exit code: 1
   Log file: /var/folders/71/fcxvkhr51hdc7vv3gs_q64sc0000gn/T/tmp-89766-UDCsrCjBfakF/error.log

Expected Behavior

The command to work and create a new monorepo.

GitHub Repo

No response

Steps to Reproduce

  1. run pnpm create create-nx-workspace@latest on macos 11 (x86)

Nx Report

>  NX   The current directory isn't part of an Nx workspace.

   To create a workspace run:
   npx create-nx-workspace@latest <workspace name>

   To add Nx to an existing workspace with a workspace-specific nx.json, run:
   npx nx@latest init

 >  NX   For more information please visit https://nx.dev/

Side note: why would a CLI not allow you to even run --help outside of a workspace directory?


### Failure Logs

```shell
## Error Log

Progress: resolved 1, reused 0, downloaded 0, added 0
Progress: resolved 127, reused 116, downloaded 2, added 0
Progress: resolved 269, reused 258, downloaded 2, added 0
Progress: resolved 455, reused 442, downloaded 2, added 0
Progress: resolved 570, reused 532, downloaded 7, added 0
Packages: +560
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 586, reused 548, downloaded 8, added 23
Progress: resolved 586, reused 548, downloaded 8, added 427
Progress: resolved 586, reused 548, downloaded 8, added 560, done
.../esbuild@0.18.20/node_modules/esbuild postinstall$ node install.js
.../esbuild@0.18.20/node_modules/esbuild postinstall: Done

devDependencies:
+ @nx/cypress 17.1.3
+ @nx/react 17.1.3
+ @nx/vite 17.1.3
+ @nx/workspace 17.1.3
+ nx 17.1.3

The dependency was already listed in devDependencies.
If you want to make it a prod dependency, then move it manually.

Done in 8s
ERROR (1) when writing 
ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~a533be78'
Error: ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~a533be78'
    at writeFileSync (node:fs:2352:20)
    at writeJsonFile (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/utils/fileutils.js:55:28)
    at writeCache (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/nx-deps-cache.js:101:43)
    at buildProjectGraphUsingProjectFileMap (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/build-project-graph.js:65:40)
    at async buildProjectGraphWithoutDaemon (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:72:27)
    at async createProjectGraphAsync (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:121:25)
    at async Object.generate (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/generate.js:214:26)
    at async Object.handler (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/command-object.js:13:22)
ERROR (2) when writing 
ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~0d0a7374'
Error: ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~0d0a7374'
    at writeFileSync (node:fs:2352:20)
    at writeJsonFile (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/utils/fileutils.js:55:28)
    at writeCache (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/nx-deps-cache.js:101:43)
    at buildProjectGraphUsingProjectFileMap (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/build-project-graph.js:65:40)
    at async buildProjectGraphWithoutDaemon (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:72:27)
    at async createProjectGraphAsync (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:121:25)
    at async Object.generate (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/generate.js:214:26)
    at async Object.handler (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/command-object.js:13:22)
ERROR (3) when writing 
ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~3a9fcf25'
Error: ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~3a9fcf25'
    at writeFileSync (node:fs:2352:20)
    at writeJsonFile (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/utils/fileutils.js:55:28)
    at writeCache (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/nx-deps-cache.js:101:43)
    at buildProjectGraphUsingProjectFileMap (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/build-project-graph.js:65:40)
    at async buildProjectGraphWithoutDaemon (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:72:27)
    at async createProjectGraphAsync (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:121:25)
    at async Object.generate (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/generate.js:214:26)
    at async Object.handler (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/command-object.js:13:22)
ERROR (4) when writing 
ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~ff182791'
Error: ENOENT: no such file or directory, open '/path/to/front/.nx/cache/project-graph.json~ff182791'
    at writeFileSync (node:fs:2352:20)
    at writeJsonFile (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/utils/fileutils.js:55:28)
    at writeCache (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/nx-deps-cache.js:101:43)
    at buildProjectGraphUsingProjectFileMap (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/build-project-graph.js:65:40)
    at async buildProjectGraphWithoutDaemon (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:72:27)
    at async createProjectGraphAsync (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/project-graph/project-graph.js:121:25)
    at async Object.generate (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/generate.js:214:26)
    at async Object.handler (/path/to/front/node_modules/.pnpm/nx@17.1.3/node_modules/nx/src/command-line/generate/command-object.js:13:22)

>  NX  Generating @nx/workspace:preset

 >  NX   ENOENT: no such file or directory, open '/var/folders/71/fcxvkhr51hdc7vv3gs_q64sc0000gn/T/tmp-89848-tN6tAagVK1EZ/package.json'

   Pass --verbose to see the stacktrace.

 >  NX   Workspace creation failed, see above.

   Pass --verbose to see the stacktrace.


### Package Manager Version

pnpm 8.11.0

### Operating System

- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)

### Additional Information

_No response_
MHarmony commented 11 months ago

Having the same issue. Latest NX version, pnpm 8.11.0, node 21.3.0.

joshua-auchincloss commented 11 months ago

Having the same issue. Latest NX version, pnpm 8.11.0, node 21.3.0.

It actually blew up all my other projects lol - getting the following error on already working source code after trying to generate a new lib


> nx run abc:serve:development

Could not find 'nx' module in this workspace. Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.

If you are leveraging \`readCachedProjectGraph()\` directly then you will need to refactor your usage to first ensure that
the ProjectGraph is created by calling \`await createProjectGraphAsync()\` somewhere before attempting to read the data.

If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
    at readCachedProjectGraph (/path/to/proj/node_modules/.pnpm/nx@17.1.3_@swc-node+register@1.6.8_@swc+core@1.3.100/node_modules/nx/src/project-graph/project-graph.js:30:15)
    at run (/path/to/proj/node_modules/.pnpm/nx@17.1.3_@swc-node+register@1.6.8_@swc+core@1.3.100/node_modules/nx/src/command-line/run/run.js:151:69)
    at process.<anonymous> (/path/to/proj/node_modules/.pnpm/nx@17.1.3_@swc-node+register@1.6.8_@swc+core@1.3.100/node_modules/nx/bin/run-executor.js:59:48)
    at process.emit (node:events:519:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

 ———————————————————————————————————
joshua-auchincloss commented 11 months ago

Works on lts/iron, temp fix by downgrading node from 21 -> 20 if anyone has the same issue until triage

jase88 commented 11 months ago

Same error here with nx 17.1.3 and node 21.3.0 downgrading to 20 helped thanks!

ysageev commented 11 months ago

Same dealio

ghost commented 10 months ago

Same issue with nx 16.8.1 and node 18.10.0 on mac.

It is consistently breaking when changing branches, so might have something to do with invalid cache / state? I don't use distributed cache.

I figured out a workaround by deleting the .nx folder completely and running my task again.

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏