nrwl / nx

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

Nx Cannot find project 'my-app' although package.json is present #13134

Closed GaryB432 closed 1 year ago

GaryB432 commented 1 year ago

Current Behavior

Nx "Cannot find" my project

Expected Behavior

I expect Nx to run my target in apps/my-app/package.json

Steps to Reproduce

npx create-nx-workspace@latest ws --preset apps --no-nx-cloud
cd ws

add apps/my-app/package.json

{
  "name": "my-app",
  "version": "0.0.0",
  "scripts": {
    "echo": "echo \"OK\""
  }
}

continue

nx echo my-app

# NX Cannot find project 'my-app'

cd ./apps/my-app
npm run echo

# OK

cd ../..
nx echo my-app

# NX Cannot find project 'my-app'

Failure Logs

As mentioned above

Environment

Node : 18.7.0
OS   : win32 x64
npm  : 8.16.0

nx : 15.0.13
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 15.0.13
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : Not Found
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.0.13
@nrwl/js : Not Found
@nrwl/linter : 15.0.13
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/rollup : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/webpack : Not Found
@nrwl/workspace : 15.0.13
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
AgentEnder commented 1 year ago

Can you run nx graph and send a picture of the graph?

GaryB432 commented 1 year ago

nx graph


NX   ENOENT: no such file or directory, open \D:\ws\apps\my-app\project.json'

Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process. If the error persists, please run "nx reset".


and an `cmd` window left open with `[process exited with code 1 (0x00000001)]` 

These results repeat if I run `nx reset`

That leading path separator looks suspicious.
GaryB432 commented 1 year ago

Was that ☝🏻all you needed? Is this still blocked?

AgentEnder commented 1 year ago

Hey, sorry, haven't gotten back to this just yet. Looking at it now, can you try running again with the following two environment variables set?

NX_DAEMON=false
NX_VERBOSE_LOGGING=true
GaryB432 commented 1 year ago

Thanks for looking (I see btw that you are a fellow midwesterner!)

Got a good stack trace from nx graph

Error: ENOENT: no such file or directory, open 'D:\ws\apps\my-app\project.json'
    at Object.openSync (node:fs:599:3)
    at readFileSync (node:fs:467:35)
    at readJsonFile (D:\ws\node_modules\nx\src\utils\fileutils.js:18:43)
    at D:\ws\node_modules\nx\src\config\workspaces.js:386:61
    at Array.forEach (<anonymous>)
    at inlineProjectConfigurations (D:\ws\node_modules\nx\src\config\workspaces.js:383:38)
    at resolveNewFormatWithInlineProjects (D:\ws\node_modules\nx\src\config\workspaces.js:379:24)
    at Workspaces.readFromWorkspaceJson (D:\ws\node_modules\nx\src\config\workspaces.js:270:16)
    at Workspaces.readWorkspaceConfiguration (D:ws\node_modules\nx\src\config\workspaces.js:59:78)
    at readAllWorkspaceConfiguration (D:\ws\node_modules\nx\src\config\configuration.js:15:72)

Yeah.. that project.json file def does not exist :)

AgentEnder commented 1 year ago

It sounds like that file definitely should exist. If you look in workspace/angular.json is there a project definition that points to apps/my-app?

GaryB432 commented 1 year ago

ahhh sure enough. Hmm such a flurry I don't know how that got there. I only executed the couple lines I put in the repro-steps above.

GaryB432 commented 1 year ago

Latest findings...

Environment variables set as above

Same repro steps as above, i.e., create-nx-workspace* and create package.json

Run nx echo my-app gives 'Cannot find project my-app but with no verbose logging

No workspace json created.

nx graph shows no errors and a graph with no projects which seems consistent with my situation

* however this did give Cannot read properties of undefined (reading 'create') but seemed to create my workspace. I guess that's another issue.

AgentEnder commented 1 year ago

Yeah, in 15 you'd need to setup yarn / npm / pnpm workspaces to enable the project inference. We look at those patterns.

GaryB432 commented 1 year ago

This seems to work in earlier 15 like 15.0.3 but that did it. Just checking my understanding....

Nx finds project.jsons by scanning but a worskspaces key is needed in root package.json for it to find my package.jsons.

Maybe just a docs label on this then. Thanks for the help!

AgentEnder commented 1 year ago

https://github.com/nrwl/nx/pull/13203 this should contain that info.

I'm going to close this out since we diagnosed the issue successfully.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.