Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nx migrate --run-migrations installs deps with legacy-peer-deps=true (even for projects without this legacy config) #26675

Open
1 of 4 tasks
nsbarsukov opened this issue Jun 25, 2024 · 3 comments
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@nsbarsukov
Copy link
Contributor

Current Behavior

Use project without legacy-peer-deps=true.

Run the following command

nx migrate --run-migrations

it logs:

 NX   Running 'npm install' to make sure necessary packages are installed

removed 297 packages, and audited 2714 packages in 4s

and then throws error:

Cannot find module 'ts-morph'

(actually, this dependency node_modules/ts-morph existed before running nx migrate --run-migrations).


Use the following command instead

npm_config_legacy_peer_deps=false nx migrate --run-migrations

Everything is okay, no error.

Expected Behavior

Default command

nx migrate --run-migrations

works without error for default project configuration (without legacy-peer-deps=true).

GitHub Repo

taiga-family/maskito#1337

Steps to Reproduce

  1. Clone this repository https://github.com/taiga-family/maskito
  2. Switch to branch nx-legacy-peer-deps-demo
  3. Run the following commands
nvm use 18
npm ci
nx migrate --run-migrations

It will throw error

  1. Then revert changes inside package-lock.json and run again npm ci.
  2. Run the following command
npm_config_legacy_peer_deps=false nx migrate --run-migrations

Everything is okay, no error.

Read more in-depth description in the body of this PR:

Nx Report

NX   Report complete - copy this into the issue template

Node   : 18.19.1
OS     : darwin-arm64
npm    : 10.2.4

nx (global)    : 19.0.3
nx             : 19.3.1
@nx/js         : 19.3.1
@nx/jest       : 19.3.1
@nx/linter     : 19.3.1
@nx/eslint     : 19.3.1
@nx/workspace  : 19.3.1
@nx/angular    : 19.3.1
@nx/cypress    : 19.3.1
@nx/devkit     : 19.3.1
@nx/react      : 19.3.1
@nx/rollup     : 19.3.1
@nrwl/tao      : 19.3.1
@nx/web        : 19.3.1
@nx/webpack    : 19.3.1
typescript     : 4.9.5

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Probably, the problem relates to the following lines from nx-library:

if (detectPackageManager() === 'npm') {
    process.env.npm_config_legacy_peer_deps ??= 'true';
}
@AgentEnder AgentEnder added the scope: core core nx functionality label Jul 8, 2024
@denny99
Copy link

denny99 commented Jul 31, 2024

I was always wondering why the npm i command, when used in the NX Plugins, removes some packages.

But perhaps this is quite important?

E.g. when upgrading packages from one version to another. Without the legacy peer deps the install might fail, as some packages will get their new version only after the upgrade (e.g. Angular CLI Version gets only upgraded during the actual migration execution)

Maybe an npm i -f might be a solution?

@cainlevy
Copy link

Workaround is to run npm install yourself:

npm install
NX_MIGRATE_SKIP_INSTALL=true npx nx _migrate --run-migrations --if-exists

I plan to make this a script in my root package.json.

@therockstorm
Copy link

Another workaround is:

npm_config_legacy_peer_deps=false npx nx migrate --run-migrations --if-exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core core nx functionality type: bug
Projects
None yet
Development

No branches or pull requests

6 participants