nrwl / nx

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

Upgrade migration from 10.3.1 to 10.4.1 fails with faulty module resolve #4100

Closed zaunermax closed 3 years ago

zaunermax commented 3 years ago

Current Behavior

when executing the migration i get the following error

Running migration @nrwl/workspace:add-explicit-dep-on-tao
Successfully finished @nrwl/workspace:add-explicit-dep-on-tao
---------------------------------------------------------
Running migration @nrwl/linter:update-eslint-configs-to-use-nx-presets
Cannot find module '@angular-devkit/core/src/experimental/workspace'
Require stack:
- /home/max/dev/myproject/node_modules/@nrwl/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.js
- /home/max/dev/myproject/node_modules/@nrwl/tao/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /home/max/dev/myproject/node_modules/@nrwl/tao/node_modules/@angular-devkit/schematics/tools/index.js
- /home/max/dev/myproject/node_modules/@nrwl/tao/src/commands/migrate.js
- /home/max/dev/myproject/node_modules/@nrwl/tao/index.js
/home/max/dev/myproject/node_modules/yargs/build/lib/yargs.js:1132
                throw err;
                ^

Error: Command failed: npx tao migrate --run-migrations=migrations.json
    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:652:15)
    at Object.handler (/home/max/dev/myproject/node_modules/@nrwl/workspace/src/command-line/nx-commands.js:74:21)
    at Object.runCommand (/home/max/dev/myproject/node_modules/yargs/build/lib/command.js:196:48)
    at Object.parseArgs [as _parseArgs] (/home/max/dev/myproject/node_modules/yargs/build/lib/yargs.js:1043:55)
    at Object.get [as argv] (/home/max/dev/myproject/node_modules/yargs/build/lib/yargs.js:986:25)
    at Object.initLocal (/home/max/dev/myproject/node_modules/@nrwl/cli/lib/init-local.js:24:13)
    at Object.<anonymous> (/home/max/dev/myproject/node_modules/@nrwl/cli/bin/nx.js:40:18)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 77769,
  stdout: null,
  stderr: null
}

Expected Behavior

The migration should run without errors.

Steps to Reproduce

Environment

nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 10.4.1
@nrwl/cypress : 10.4.1
@nrwl/eslint-plugin-nx : 10.4.1
@nrwl/express : Not Found
@nrwl/jest : 10.4.1
@nrwl/linter : 10.4.1
@nrwl/nest : 10.4.1
@nrwl/next : Not Found
@nrwl/node : 10.4.1
@nrwl/react : 10.4.1
@nrwl/schematics : Not Found
@nrwl/tao : 10.4.1
@nrwl/web : 10.4.1
@nrwl/workspace : 10.4.1
typescript : 4.1.1-rc
zaunermax commented 3 years ago

When I npm ls the dependency, it seems to be installed properly though

npm ls @angular-devkit/core
myproject@0.0.0 /home/max/dev/myproject
├── @angular-devkit/core@11.0.1 
├─┬ @nestjs/schematics@7.2.2
│ ├── @angular-devkit/core@11.0.0 
│ └─┬ @angular-devkit/schematics@11.0.0
│   └── @angular-devkit/core@11.0.0 
├─┬ @nrwl/cli@10.4.1
│ └─┬ @nrwl/tao@10.4.1
│   ├── @angular-devkit/core@10.1.7 
│   └─┬ @angular-devkit/schematics@10.1.7
│     └── @angular-devkit/core@10.1.7  deduped
├─┬ @nrwl/cypress@10.4.1
│ ├─┬ @angular-devkit/architect@0.1001.7
│ │ └── @angular-devkit/core@10.1.7 
│ ├── @angular-devkit/core@10.1.7 
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7  deduped
├─┬ @nrwl/eslint-plugin-nx@10.4.1
│ └── @angular-devkit/core@10.1.7 
├─┬ @nrwl/jest@10.4.1
│ ├── @angular-devkit/core@10.1.7 
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7  deduped
├─┬ @nrwl/nest@10.4.1
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7 
├─┬ @nrwl/node@10.4.1
│ ├─┬ @angular-devkit/build-webpack@0.1001.7
│ │ └── @angular-devkit/core@10.1.7 
│ ├── @angular-devkit/core@10.1.7 
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7  deduped
├─┬ @nrwl/react@10.4.1
│ ├── @angular-devkit/core@10.1.7 
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7  deduped
├─┬ @nrwl/web@10.4.1
│ ├── @angular-devkit/core@10.1.7 
│ └─┬ @angular-devkit/schematics@10.1.7
│   └── @angular-devkit/core@10.1.7  deduped
└─┬ @nrwl/workspace@10.4.1
  ├── @angular-devkit/core@10.1.7 
  ├─┬ @angular-devkit/schematics@10.1.7
  │ └── @angular-devkit/core@10.1.7  deduped
  └─┬ @nrwl/cli@10.4.1
    └─┬ @nrwl/tao@10.4.1
      └── @angular-devkit/core@10.1.7  deduped
mandarini commented 3 years ago

Hi there @zaunermax !

Unfortunately I could not reproduce your issue..

Let me tell you the steps I followed, to see if we're on the same page:

  1. I generated an Nx workspace with version 10.3.1: npx create-nx-workspace@10.3.1 my-wksp
  2. I ran the nx migrate command: nx migrate @nrwl/workspace@10.4.1
  3. Then, I ran yarn to install any missing dependencies that the nx migrate command introduced, when it updated my package.json
  4. Finally, I ran nx migrate --run-migrations=migrations.json to complete the migration.

All steps ran successfully with no errors.

Can you please let me know if you followed the same steps? Could you have, potentially, forgotten to ran yarn after the first nx migrate command?

zaunermax commented 3 years ago

Hi @mandarini, thanks for the quick answer.

We use npm, but I think that shouldn't matter :thinking: But yes, first I executed nx migrate latest, then I installed deps with npm i and finally i tried to run the migrations with nx migrate --run-migrations=migrations.json

Seems to be a really weird edge case with our repo then :thinking:

EDIT: installing packages with yarn did the trick :sweat_smile:

The question now is, why can't it resolve the dependency when installing packages with npm :thinking:

For anyone that stumbles across this, I executed rm -rf node_modules and then yarn, after that, running the migrations went throught without any issues, after that i removed the yarn lock file and reinstalled the packages with npm, which seems to work fine everywhere else :raised_hands:

Also, I now tried to upgrade to latest, which is, at the time of writing, the version 10.4.4 - first with npm it did fail again, but it eventually worked with yarn.

Somehow the require call in node_modules/@nrwl/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.js on line 4 is the reason why the migration crashes :thinking:

JonnyBGod commented 3 years ago

I hit the same problem migrating one lerna repo with two nx workspaces angular/xplat workspace and one nestjs after upgrading to angular 11.

Angular dev-kit moved workspace from experimental to src folder and even though nx still installs the older dev-kit version, npm is trying to resolve from the upstream installation. Yarns probably resolves it differently and that is why the different results.

zaunermax commented 3 years ago

Wow, good catch :clap: I didn't really have time to go into the topic more deeply as I had a set time constraint for upgrading nx. I was thrown off, because npm ls would resolve the dep so I was confused

brendanalexdr commented 3 years ago

With the hint from @zaunermax I first ran npm install THEN nx migrate --run-migrations=migrations.json

zaunermax commented 3 years ago

With the hint from @zaunermax I first ran npm install THEN nx migrate --run-migrations=migrations.json

when migrating, you always have to run install first - it just wouldn't resolve correctly if I installed it with npm - I had to install deps with yarn to get it to work...

mandarini commented 3 years ago

Hi @zaunermax ! Do you think that we could close this issue now?

zaunermax commented 3 years ago

@mandarini I think that it is up to you, I could fix it by just installing my deps via yarn, then doing the upgrade and then using npm again. If this issue is not important in the grand scheme of things it's completely fine by me don't worry about me, I am just reporting stuff if i encounter some stuff :raised_hands:

FrozenPandaz commented 3 years ago

Going to close this as this discussion seems to have resolved the issue :smiley:.

Thanks everyone!

zaunermax commented 3 years ago

Yes, sorry for not closing it 🙈

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.