nrwl / nx

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

Nx migrate is fork bombing my laptop #9345

Closed andynunes closed 2 years ago

andynunes commented 2 years ago

Current Behavior

When running nx migrate to latest version, a new node process is created approximately every second and the processes hang and continue to build up with no apparent ability to stop them from spawning.

Expected Behavior

Nx migrate completes by using a single node process and doesn't fork bomb my computer.

Steps to Reproduce

  1. Open nx project at version 13.8.5 using WebStorm
  2. WebStorm plugin prompts to run nx migrate to 13.9.0
    17:39   Nx Workspace Migration
            A new @nrwl/nx version is available 13.9.0
            Nx Migrate Workspace
  3. Click on Nx Migrate Workspace

Failure Logs

Excerpt from ps

 4771   ??  S      0:00.17 node /var/folders/0v/w7pfhhc57yj4ywtgvb9zzn280000gn/T/tmp-4761-4NG11sHOhBne/node_modules/.bin/tao migrate @nrwl/workspace
 4774   ??  S      0:00.16 node /var/folders/0v/w7pfhhc57yj4ywtgvb9zzn280000gn/T/tmp-4771-sAsR6ZWwMnDl/node_modules/.bin/tao migrate @nrwl/workspace
 4782   ??  S      0:00.17 node /var/folders/0v/w7pfhhc57yj4ywtgvb9zzn280000gn/T/tmp-4774-ykY1KTRsv1pr/node_modules/.bin/tao migrate @nrwl/workspace
 4804   ??  S      0:00.15 node /var/folders/0v/w7pfhhc57yj4ywtgvb9zzn280000gn/T/tmp-4782-7CGydIjyZB6u/node_modules/.bin/tao migrate @nrwl/workspace
☁  ~  ps x | grep node | grep -v grep | wc -l
     120
☁  ~  ps x | grep node | grep -v grep | wc -l
     123

Environment

   Node : 14.18.1
   OS   : darwin arm64
   npm  : 8.3.0

   nx : 13.8.5
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.5
   @nrwl/cypress : undefined
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.5
   @nrwl/eslint-plugin-nx : 13.8.5
   @nrwl/express : undefined
   @nrwl/jest : 13.8.5
   @nrwl/js : 13.8.5
   @nrwl/linter : 13.8.5
   @nrwl/nest : 13.8.5
   @nrwl/next : undefined
   @nrwl/node : 13.8.5
   @nrwl/nx-cloud : 13.1.6
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : undefined
   @nrwl/tao : 13.8.5
   @nrwl/web : undefined
   @nrwl/workspace : 13.8.5
   typescript : 4.5.5
   rxjs : 7.5.4
   ---------------------------------------
   Community plugins:
andynunes commented 2 years ago

After several failed attempts to migrate project into a nx project at my startup, I've taken a stab at starting fresh with nx at a different organization. However, I've encountered two showstopper bugs just in the process of setting up the scaffolding in the first week.

This influx of new show-stopping issues is making me lose confidence and seriously reconsider nx altogether.

jahumes commented 2 years ago

I believe this is an issue with Nx 13.9.0 and the switch away from tao. I have dug into the code because I had a migration 2 days ago that works just fine, but now my migrations are doing the same as above. From what I can gather, the code that calls the migrate command is based in version 13.8.5 (or really any version in 13 before 13.8.5. I have tried 13.1.4 and 13.7.3 as well). When this code runs, it installs the most recent version of tao and the nx cli into a temp folder. https://github.com/nrwl/nx/blob/fd645460214bfb45726f983c1ce570a4bfb4e2fe/packages/workspace/src/command-line/nx-commands.ts#L288-L295 Once it does this, it returns this as the version that should be used to make the migration call. The issue seems to stem from pulling in the local project version of nx again here: https://github.com/nrwl/nx/blob/1b7a3b2b74c4395da55bffabd4923e973f6c58de/packages/nx/bin/nx.ts#L37-L70 Based on the comments, it looks like it is supposed to be going down line 47 to use the local nx in the temp directory, but instead it fails the if statement on line 46 and ends up thinking it is running the globally installed cli and hands the process back off to the local version which is the original file as the parent process kicking off an infinite loop.

jahumes commented 2 years ago

I can say that by changing line 597 below to 13.8.8 fixes this issue.

https://github.com/nrwl/nx/blob/fd645460214bfb45726f983c1ce570a4bfb4e2fe/packages/workspace/src/command-line/nx-commands.ts#L595-L600

iamrommel commented 2 years ago

same here, try to migrate to version 13.9.0 really causes my laptop to explode. (joke aside)

And this is a show stopper for me as i cannot get the latest fix about the storybook staticDir fix which is available on that version. nx migrate latest hangs forever for me. :(

andynunes commented 2 years ago

Thanks @jahumes for the detailed validation and @leosvelperez for the fast fix and release!

I just ran the migration to 13.9.1. After running npm install, I'm getting the following error:

☁  services [1-nx-scaffolding] ⚡  nx run user-service:build
Unexpected error:
Error: Cannot find module 'nx/src/cli/run-cli.js'
AgentEnder commented 2 years ago

@andynunes can you verify that "nx" is listed as a dependency in package.json? Verify it and all other nrwl packages (aside from cloud) are at 13.9.1.

jamesmcglinn commented 2 years ago

@andynunes I had the same issue after running nx migrate (with npm install and running migrations) then as prompted running npm install -g nx.

In my case running npm install again fixed the problem.

Tirke commented 2 years ago

@AgentEnder That fixed it for me but why can't the migration handle adding nx to devDeps? It's a bit weird that it is now mandatory because it was not before.

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.