Skip to content
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

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

Closed
GaryB432 opened this issue Nov 11, 2022 · 12 comments
Closed

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

GaryB432 opened this issue Nov 11, 2022 · 12 comments

Comments

@GaryB432
Copy link

GaryB432 commented Nov 11, 2022

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
Copy link
Member

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

@GaryB432
Copy link
Author

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
Copy link
Author

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

@AgentEnder
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Author

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
Copy link
Member

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

@GaryB432
Copy link
Author

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
Copy link
Member

#13203 this should contain that info.

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

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants