nrwl / nx

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

Error while loading rule '@nrwl/nx/enforce-module-boundaries': ENOENT: no such file or directory, open 'nx.json' Occurred while linting #10493

Closed kentytik closed 2 years ago

kentytik commented 2 years ago

Current Behavior

ESLINT error output: Error while loading rule '@nrwl/nx/enforce-module-boundaries': ENOENT: no such file or directory, open /home/user/monoreporootfolder/nx.json' Occurred while linting /home/user/monoreporootfolder/nxmonorepo/apps/toh/src/app/any-open-file.ts

The error log shows up in the vscode ESLINT output. The development environment is the monorepo hosted on a debian-based server with vscode accessing the monorepo via the Microsoft Remote-SSH extension.

Additionally, the NX Console extension isn't working.

It appears nx is looking for the 'nx.json' config file in the root folder of the main NPM worksaces-based monorepo (i.e. npmworkspacesmonorepofolder) instead of in the 'nx workspace folder' that's a subfolder one level down under the main monorepo

The nx cli works perfectly on the remote SSH host with the schematics, and to build, serve, etc., otherwise.

Expected Behavior

nx should find the 'nx.json' config. file in the 'nx workspace folder' instead of looking up one level, i.e. in the root folder of the NPM worksaces-based monorepo. Thus, there shouldn't be an ESLINT linting error if it finds the 'nx.json' file.

The NX Console vscode extension must work well and provide all the 'generate' options

Steps to Reproduce

  1. 'Monorepo' based on NPM workspaces with the following folder structure: [npmworkspacesmonorepofolder] NPM workspaces monorepo root folder -- [nxmonorepo] nx monorepo folder (new workspace being implemented to gradually transition to nrwl nx monorepo) -- [other workspace/repo] other older workspace folder with several packages -- [other workspace/repo] another older workspace folder with several packages
  2. An/any minimal angular app workspace created in the [nxmonorepo] folder
  3. vscode open any-open-file.ts file
  4. Throws up ESLINT error: Error while loading rule '@nrwl/nx/enforce-module-boundaries': ENOENT: no such file or directory, open /home/user/monoreporootfolder/nx.json' Occurred while linting /home/user/monoreporootfolder/nxmonorepo/apps/toh/src/app/any-open-file.ts

Failure Logs

Error while loading rule '@nrwl/nx/enforce-module-boundaries': ENOENT: no such file or directory, open '/mnt/usbhdd1/home/user/npmmonorepofolder/nx.json' Occurred while linting /home/user/npmmonorepofolder/nxworkspace/apps/toh/src/app/any-open-file.ts

Environment

Node : 16.15.0 OS : linux x64 npm : 8.10.0

nx : 14.1.9 @nrwl/angular : 14.1.9 @nrwl/cypress : 14.1.9 @nrwl/detox : Not Found @nrwl/devkit : 14.1.9 @nrwl/eslint-plugin-nx : 14.1.9 @nrwl/express : 14.1.9 @nrwl/jest : 14.1.9 @nrwl/js : 14.1.9 @nrwl/linter : 14.1.9 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : 14.1.9 @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : Not Found @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.1.9 @nrwl/web : Not Found @nrwl/workspace : 14.1.9 typescript : 4.6.4

Community plugins: @nguniversal/express-engine: 13.1.1 rxjs: 6.6.7 @nguniversal/builders: 13.1.1

AgentEnder commented 2 years ago

@kentytik Can you open an issue on https://github.com/nrwl/nx-console for the console portion of this issue?

meeroslav commented 2 years ago

Hi @kentytik, thank you for opening the issue.

Unfortunately, I don't think this can ever work the way you set it up.

A lot of the code in nx expects it to be in charge of the monorepo or at least share the control on the root level. If you would try this with the latest version, your error would now be different, but you would still have an issue running any command.

The issue you are facing originates from the fact that we search for nx in order to know how to configure things. If nx is not found, the latest code will assume the default preset for the nx configuration and will try to run the nx commands on the process's CWD. This is in your case /home/user/monoreporootfolder. Unfortunately, there is no nx package set up on that level. In order for any Nx command to work (including the linter rule) you need to have a built dependency graph (located in node_modules/.cache/nx) which gets built on init and then refreshed every time you run any Nx command from the terminal. But since VS Code is running the linter from the root, it will never find the nxdeps.json and will bail out with a warning message:

WARNING No cached ProjectGraph is available. The rule will be skipped.

For the same reason, the Nx Console extension will fail. Since there is no nx.json or nx installed in the root, it assumes this is not an Nx monorepo. The alternative would be to look in every package to check if that is an Nx monorepo, but what happens if it finds two? Where should e.g. nx g @nrwl/js mylib be generated?

If I'm missing something, please feel free to provide more details and ideally a minimal repo showcasing this. Otherwise, I would kindly ask you to close this issue.

kentytik commented 2 years ago

I moved nx up to root of the monorepo so it shares the control on the root level, in a way, together with NPM workspaces for managing package dependencies of projects in the monorepo. Smooth sailing so far.

I had used nx previously to manage/control an all-Angular monorepo, but now expanded it to cover Angular, NextJs, node/express and web apps. I must say it's a completely better developer experience with nx. I hope that continues, though. ;-)

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.