Nx: Upgrade migration from 10.3.1 to 10.4.1 fails with faulty module resolve

Created on 17 Nov 2020  ยท  8Comments  ยท  Source: nrwl/nx

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
misc bug

All 8 comments

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

npm ls @angular-devkit/core
[email protected] /home/max/dev/myproject
โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”œโ”€โ”ฌ @nestjs/[email protected]
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected] 
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ””โ”€โ”ฌ @nrwl/[email protected]
โ”‚   โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚   โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚     โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ”œโ”€โ”ฌ @angular-devkit/[email protected]
โ”‚ โ”‚ โ””โ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ””โ”€โ”€ @angular-devkit/[email protected] 
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected] 
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ”œโ”€โ”ฌ @angular-devkit/[email protected]
โ”‚ โ”‚ โ””โ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ”œโ”€โ”ฌ @nrwl/[email protected]
โ”‚ โ”œโ”€โ”€ @angular-devkit/[email protected] 
โ”‚ โ””โ”€โ”ฌ @angular-devkit/[email protected]
โ”‚   โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
โ””โ”€โ”ฌ @nrwl/[email protected]
  โ”œโ”€โ”€ @angular-devkit/[email protected] 
  โ”œโ”€โ”ฌ @angular-devkit/[email protected]
  โ”‚ โ””โ”€โ”€ @angular-devkit/[email protected]  deduped
  โ””โ”€โ”ฌ @nrwl/[email protected]
    โ””โ”€โ”ฌ @nrwl/[email protected]
      โ””โ”€โ”€ @angular-devkit/[email protected]  deduped

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 [email protected] my-wksp
  2. I ran the nx migrate command: nx migrate @nrwl/[email protected]
  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?

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:

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.

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

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

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...

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zachnewburgh picture zachnewburgh  ยท  3Comments

MichaelWarneke picture MichaelWarneke  ยท  3Comments

olakara picture olakara  ยท  3Comments

jon301 picture jon301  ยท  3Comments

markphip picture markphip  ยท  3Comments