npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] peerDependency not installed (workspaces) #4084

Open kirrg001 opened 2 years ago

kirrg001 commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

Refs https://github.com/npm/cli/issues/2600

I am using NPM workspaces. I moved all my dev dependencies to the root package.json (because I was running into https://github.com/npm/cli/issues/4056)

devDependencies: {
   ...
   "mssql": "^7.1.0",
   "knex": "^0.21.21",
   ....
}

knex@0.21 has a peerDependency to mssql@6 (see)

I am getting an error when running npm install

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @projectname/root@undefined
npm ERR! Found: mssql@7.1.0
npm ERR! node_modules/mssql
npm ERR!   dev mssql@"^7.1.0" from the root project
npm ERR!   peerOptional mssql@"*" from typeorm@0.2.41
npm ERR!   node_modules/typeorm
npm ERR!     dev typeorm@"^0.2.37" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev knex@"^0.21.21" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: mssql@7.3.0
npm ERR! node_modules/mssql
npm ERR!   peerOptional mssql@"^6.2.1" from knex@0.21.21
npm ERR!   node_modules/knex
npm ERR!     dev knex@"^0.21.21" from the root project

I tried --legacy--peer-deps, but this is not what I want. This flag will just ignore the peer dependency. Knex will then use mssql@7!

Expected Behavior

I expected that npm provides a way to install both versions.

node_modules
    mssql@7
    knex
        node_modules
            mssql@6

Steps To Reproduce

See above.

Environment

ghost commented 2 years ago

Facing similar issue. We are using knex and objection. In our case, some of the direct dependencies are not installed as well in workspaces. Works fine when these packages are installed in the root.

ghost commented 2 years ago

Facing similar issue. We are using knex and objection. In our case, some of the direct dependencies are not installed as well in workspaces. Works fine when these packages are installed in the root.

this happens if node_modules directories are in the workspace directories. a fresh installation without lockfile and node_modules directory. the issue doesn't happen.

oswaldoacauan commented 2 years ago

We still see the same issue when having different Next and React versions in two different workspaces.

Same deal as mentioned above. If we run the npm install inside the workspace folder it works as expected.

easa commented 2 years ago

I guess it's not a bug yet there is no instruction about how to handle this conflicts. I couldn't find anything in the docs and I would be grateful if you could explain what this error means in workspaces and what we need to do to fix it.

danielritter commented 5 months ago

same problem here