nrwl / nx-console

Nx Console is the user interface for Nx & Lerna.
https://nx.dev
MIT License
1.31k stars 213 forks source link

The current directory isn't part of an Nx workspace #1122

Closed KerickHowlett closed 2 years ago

KerickHowlett commented 3 years ago

Current Behavior

Whenever I attempt to use the Nx Console to inject an Angular app into the repo, every dry-run returns with an error that reads:

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

This isn't the case at all, as I checked over ten times to make sure I was in the right directory. I even went as far as to see if there was something up with my integrated terminal -- found nothing of the sort.

Expected Behavior

I expect it to generate an Angular app within the NRWL repo as it should. Nothing complicated.

Steps to Reproduce

  1. Have VS Code with the Nx Console extension installed and running on it.
  2. While in a terminal of your choosing, use the command npx create-nx-workspace <project_name> to create the workspace. (I use Yarn, but this happens to me using NPM as the package manager as well.)
  3. Open the repo using VSCode.
  4. While in the terminal -- doesn't matter if it's VSCode's integrated terminal or an external instance -- and while in the project's root directory, enter the following command, punctuated with Enter:
    npm i --save-dev @nrwl/angular

    OR

    yarn add -D @nrwl/angular

    (I always did the latter, just FYI.)

Failure Logs

While filling out the form in the console, it executes dry-runs, which always prints out these errors (and it prints out the same one if I attempt to actually execute the widget, anyway).

(I censored out two directory names, but they have no bearing on the bug.)

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

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

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

The terminal process "/usr/bin/bash '-l', '-c', '/home/<profile_name>/projects/challenges/<project_name>/node_modules/.bin/nx generate @nrwl/angular:application --name=test --no-interactive --dry-run', 'nx generate @nrwl/angular:application --name=test --no-interactive --dry-run'" failed to launch (exit code: 1).

My Discovery

The problem seems to be a result of the dir argument passed into findWorkspaceRoot() in the @nrwl/cli dependency, which is process.cwd(). It's passing the root directory of my filesystem ( / ) instead of the root directory of my project.

Environment

Not a part of the printed report, but I'm working from a WSL2 environment, and I install Node via NVM.

Node : 15.14.0
  OS   : linux x64
  yarn : 1.22.10

  nx : Not Found
  @nrwl/angular : 12.1.1
  @nrwl/cli : 12.1.1
  @nrwl/cypress : 12.1.1
  @nrwl/devkit : 12.1.1
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 12.1.1
  @nrwl/linter : 12.1.1
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : 8.12.11
  @nrwl/tao : 12.1.1
  @nrwl/web : Not Found
  @nrwl/workspace : 12.1.1
  @nrwl/storybook : Not Found
  @nrwl/gatsby : Not Found
  typescript : 4.1.5
prodkt commented 2 years ago

This is happening to us now as well. Do you need all our people to submit bug reports or is this prioritized and a temp fix offered?

Cammisuli commented 2 years ago

@prodkt if you can, get your people to thumbs up the OP. I'll try to find some time this week to solve this. I couldn't reproduce this last time, but maybe something changed recently that made this easier to produce.

KerickHowlett commented 2 years ago

I forgot I even filed this issue, it was so long ago. lol

Even though I still use WSL2 on my personal machine along with all the other specs I listed, I'm no longer having this issue, so I'm not sure how I fixed it, or if it was even I who did something to fix it.

Let me know if you'd like for me to post any particular details about my system or settings, and I'll happily help when I have the time.

I've had to do several hard re-installs of Windows since then, but my VSCode settings are synched, and I've acquired far more knowledge on bash, UNIX, add WSL since then, so I should be able to provide far more helpful insight compared to when I originally posted this thread.

johannesschobel commented 2 years ago

i stumble upon this issue in combination with my current setup, where i develop my app in a WSL2 ubuntu system. everything related to the development (node, npm, nrwl/nx, ...) is installed within WSL. However, as i really love the GitHub Desktop Git client, i have this client installed on my regular computer running on windows.

I have GitHooks enabled through husky.

When i commit through VSCode, everything works. When i use GitHub Desktop i get the previously described error message.

Can somebody help? All the best, Johannes

johannesschobel commented 2 years ago

i found out, that the error message was misleading. It was - in fact - an issue with the cmd that was not able to properly execute UNC Paths (i.e., wsl is mounted to \\wsl$\...).

In order to solve the issue, i had to add a new windows registry flag

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\DisableUNCCheck

as a DWord (32bit) and set the value to1. Setting the value to0(or removing the flag) will show thecannot handle unc paths` error message, which was the root cause of the issue itself.

Cammisuli commented 2 years ago

Oh that's interesting. I feel like that's not something that needs to be done though.

I'm gonna have to investigate wsl2 more and make sure it works well.

KerickHowlett commented 2 years ago

That is odd. While I still don't know how I got mine to work, I know I never touched the registry in order to do it.

Cammisuli commented 2 years ago

Well, I finally got around to installing windows + wsl2 + ubuntu, and things appear to be working. I didn't have to set up any registry settings (just some config settings for some network stuff to actually install npm dependencies, that was a struggle 😓 ), or do anything else than what was provided by Microsoft documentation.

I also had the code located within the wsl file system, and didn't go cross boundaries - ie opening code with /mnt/c/etc, or opening code with \\$wsl\etc

image
Cammisuli commented 2 years ago

I'm going to have to close this as it is working as expected, and I haven't received any new info for a couple weeks. If it still happens, please provide more information (ie, how are you accessing the project, what version of wsl are you using, etc).

o-glethorpe commented 2 years ago

Just got this same message today. Created a new workspace on windows then got the repo on a mac, installed everything then got the message: The current directory isn't part of an Nx workspace.

bill-mcgrory commented 2 years ago

I got this message, and it appears to be because my global copy of @nrwl/cli was behind my workspace repo

abductedMind commented 1 year ago

Just figured out why I was having a similar issue. There was a conflict between the globally installed Nx version and the locally installed version. I needed to remove the globally installed version of Nx because it was different in different projects.

travissimon commented 1 year ago

I'm now encountering this after upgrading to nx version 16, also using WSL2.

wsl --version

WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1702

git diff package.json

diff --git a/package.json b/package.json
index a7f40c9..18fd2f4 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,6 @@
                "@angular/router": "15.1.3",
                "@elastic/elasticsearch": "^7.12.0",
                "@juggle/resize-observer": "^3.3.1",
-               "@nrwl/angular": "15.6.3",
                "axios": "^0.21.0",
                "bcrypt": "^5.0.0",
                "cheerio": "^1.0.0-rc.5",
@@ -63,59 +62,62 @@
                "ngx-material-timepicker": "^5.5.3",
                "prom-client": "^13.1.0",
                "reconnecting-websocket": "^4.4.0",
-               "rxjs": "~7.5.0",
+               "rxjs": "7.8.1",
                "sanitize-html": "^2.3.0",
                "slug": "^4.1.0",
                "temp": "^0.9.4",
                "tslib": "^2.3.0",
                "uuid": "^8.3.0",
                "ws": "^7.4.6",
-               "zone.js": "~0.11.4"
+               "zone.js": "~0.11.4",
+               "@nx/angular": "16.2.1"
        },
        "devDependencies": {
                "@angular-devkit/build-angular": "15.1.4",
-               "@angular-eslint/eslint-plugin": "15.0.0",
-               "@angular-eslint/eslint-plugin-template": "15.0.0",
-               "@angular-eslint/template-parser": "15.0.0",
+               "@angular-devkit/core": "15.1.4",
+               "@angular-devkit/schematics": "15.1.4",
+               "@angular-eslint/eslint-plugin": "16.0.2",
+               "@angular-eslint/eslint-plugin-template": "16.0.2",
+               "@angular-eslint/template-parser": "16.0.2",
                "@angular/cli": "~15.1.0",
                "@angular/compiler-cli": "15.1.3",
                "@angular/language-service": "15.1.3",
-               "@nrwl/cli": "15.6.3",
-               "@nrwl/cypress": "15.6.3",
-               "@nrwl/eslint-plugin-nx": "15.6.3",
-               "@nrwl/express": "15.6.3",
-               "@nrwl/jest": "15.6.3",
-               "@nrwl/linter": "15.6.3",
-               "@nrwl/node": "15.6.3",
-               "@nrwl/workspace": "15.6.3",
+               "@nx/cypress": "16.2.1",
+               "@nx/eslint-plugin": "16.2.1",
+               "@nx/express": "16.2.1",
+               "@nx/jest": "16.2.1",
+               "@nx/linter": "16.2.1",
+               "@nx/node": "16.2.1",
+               "@nx/workspace": "16.2.1",
+               "@schematics/angular": "15.1.4",
                "@types/express": "4.17.13",
                "@types/htmlparser2": "^3.10.3",
-               "@types/jest": "28.1.8",
+               "@types/jest": "29.4.4",
                "@types/luxon": "^3.1.0",
                "@types/mkdirp": "^1.0.2",
                "@types/node": "18.7.1",
                "@types/uuid": "^8.3.1",
                "@types/webpack": "4.41.21",
                "@types/ws": "^7.4.6",
-               "@typescript-eslint/eslint-plugin": "5.44.0",
-               "@typescript-eslint/parser": "5.44.0",
+               "@typescript-eslint/eslint-plugin": "5.59.6",
+               "@typescript-eslint/parser": "5.59.6",
                "codelyzer": "6.0.1",
                "copy-webpack-plugin": "^9.0.1",
-               "cypress": "^12.2.0",
+               "cypress": "12.12.0",
                "dotenv": "10.0.0",
                "eslint": "8.15.0",
                "eslint-config-prettier": "8.1.0",
                "eslint-plugin-cypress": "^2.10.3",
-               "jest": "28.1.3",
-               "jest-environment-jsdom": "28.1.1",
-               "jest-preset-angular": "12.2.3",
+               "jest": "29.4.3",
+               "jest-environment-jsdom": "29.4.3",
+               "jest-preset-angular": "13.1.1",
                "ndb": "^1.1.5",
-               "nx": "15.6.3",
+               "nx": "16.2.1",
                "prettier": "2.8.0",
-               "ts-jest": "28.0.8",
+               "ts-jest": "29.1.0",
                "ts-node": "10.9.1",
                "tslint": "6.1.3",
-               "typescript": "4.8.4",
+               "typescript": "5.0.4",
                "webpack": "^5.47.0",
                "webpack-merge": "^5.8.0",
                "webpack-node-externals": "^3.0.0"

I attempted to upgrade my global nx to synch any changes. Note that I'm using NVM.

which nx /home/tsimon/.nvm/versions/node/v16.17.0/bin/nx

stat /home/tsimon/.nvm/versions/node/v16.17.0/bin/nx

  File: /home/tsimon/.nvm/versions/node/v16.17.0/bin/nx -> ../lib/node_modules/nx/bin/nx.js
  Size: 32              Blocks: 0          IO Block: 4096   symbolic link
Device: 820h/2080d      Inode: 338339      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/  tsimon)   Gid: ( 1000/  tsimon)
Access: 2023-05-22 22:17:57.145544721 +1000
Modify: 2023-05-22 22:15:33.354556237 +1000
Change: 2023-05-22 22:15:33.354556237 +1000
 Birth: -
KerickHowlett commented 1 year ago
  1. Do you have nx installed globally?
  2. You appear to be using Node 16, try installing Node 18 (LTS) or Node 20 (Latest).
travissimon commented 1 year ago

Wow, OK, so I did manage to fix this error, although I'm not entirely sure what exactly caused the issue or how I fixed it.

First, I did upgrade node to the latest. Thank you for that suggestion.

Then I got to the point where I had a global nx installed, but it would not work (after upgrading). I would see:

$ nx build

The current directory is not part of an Nx workspace

$ npx nx build ... ( various building noises ) ...

In then end, I managed to solve it by removing every trace of nx from any global namespace and then doing another global install. I don't fully understand it, but I'm happy to have it working and upgrading again.

KerickHowlett commented 1 year ago

If I were to guess, it may have something to do with how your nvm is configured to handle its bin files and PATH.

There is a way to set it up where your PATH is always pointed to a symlink, which points to the version of Node you're actively using by enabling a specific environment variable.

The details on how to do it will be in their official documentation.

It could have also been some scoping conflict, but I'm just throwing out theories at this point.

Nx always recommend to use their CLI through the one installed in your dev dependents, so there isn't any versioning conflicts is why I'm making this guess.

ipsjolly commented 7 months ago

Try removing any global instances of nx :

npm rm --global nx @nrwl/cli @nrwl/tao

Then update the nx to the latest version at your project level in package.json devDeps:

In my case:

... "devDependencies": { ... "nx": "~18.2.2", },

Make sure to add ~ in front of the version to fetch latest and install it:

npm install @nx --save-dev

demisx commented 4 months ago

It happened to me because I removed <workspace-name>/node_modules/ directory in my workspace. Had to run npm install first for this error to go away.