Description
Current Behavior
When I created a nx monorepo following the documentation using the single version strategy (where the documentation claims that a package.json
is only needed at the workspace root but not for the individual apps), everything worked fine so far, could build the first app which was automatically added by the generator.
I already had issues in the beginning tho, that some nx commands (some plugins perhaps, I used a vite typescript react app with eslint and prettier) failed because they wanted a package.json at the root of the project (meaning the app, not the workspace), so I searched a while online and just added a stupid simple package.json
to the app with only the name, the version and nothing else.
It worked again, nx built the project graph and built the app and served it.
After some days I wanted to add a second app to my monorepo.
Directly with the @nx/react generator in the VSCode extension to generate my app.
Settings were:
directory: apps/app2
bundler: vite
linter: eslint
name: myAppName
unitTestRunner: vitest
compiler: babel
e2eTestRunner: none
strict: true
style: tailwind
Once I generated this app, everything began to hang in the VSCode nx console. It tried to refresh the workspace indefinitely.
I started using terminal console commands manually like npx nx reset
, npx nx run build:app2
and waited and waited and waited.
Deleted node_modules completely and ran npm i
from scratch, installed latest node LTS 22 version on the Windows host machine, restarted the computer, and so on.
Deleted the second app again from the repo and it worked again and built the app.
Re-generated the second app, freeze.
Deleted app2 again, worked again,
Re-generated, freeze again.
Always with Calculating the project graph on the Nx Daemon is taking longer than expected. Re-run with NX_DAEMON=false to see more details.
then NX_DAEMON=false npx nx run build:app2
--> hangs at Creating project graph dependencies with 6 plugins
.
sometimes just Failed to process project graph. Run "nx reset" to fix this
.
Also, any nx command failed, not just for app2, but also for app1.
When I finally figured, the only difference between app1 and app2 was, that the generator did not add a package.json to the freshly created app2, I copied the slim one from app1, renamed the name field for app2 and voila, it worked again.
Content of the package.json on app-level:
{
"name": "@appX",
"version": "0.0.0",
"private": true,
"dependencies": {}
}
Expected Behavior
- nx commands should not hang up without error messages if
package.json
files are missing. - The nx documentation should not falsely claim that, for single-version monorepos, a
package.json
is not needed per app, but only one per workspace root, which apparently is wrong (at least in my configured setup, where I wanted to have type: module in my workspace root, and with the tools that I used). - the @nx/react generator should add a package.json to the generated app
- or, if all of this is a wrong configuration on my side, the nx documentation should clearly show how to configure the monorepo with type:module (for ESM type projects (not talking about nx plugins, but about my project code)) without package.jsons in each app folder, because it does not work with this setup, as some plugins will complain about the missing package.json, being it typescript, eslint, vite or something else.
GitHub Repo
No response
Steps to Reproduce
- in a fresh location
npm i -D @nx/react/latest
(selecting vite, typescript, eslint, prettier) - add
"type": "module"
to workspace rootpackage.json
tsconfig.base.json
:"moduleResolution": "bundler"
,"target": "es2022"
,"lib": ["es2023", "DOM", "DOM.Iterable"]
this should be the key changes where trying to build the app produce some "package.json missing" errors.
Nx Report
Node : 22.13.0
OS : win32-x64
Native Target : x86_64-windows
npm : 11.0.0
nx : 20.3.1
@nx/js : 20.3.1
@nx/eslint : 20.3.1
@nx/workspace : 20.3.1
@nx/devkit : 20.3.1
@nx/eslint-plugin : 20.3.1
@nx/module-federation : 20.3.1
@nx/react : 20.3.1
@nx/vite : 20.3.1
@nx/web : 20.3.1
typescript : 5.7.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/js/typescript
Failure Logs
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response