Replies: 37 comments 17 replies
-
Peer dependencies are not installed because
Peer dependencies are intended to be used by pluggable packages and are resolved from higher in the dependency tree. They are not supposed to be resolved from down the dependency tree. If they are resolved that way accidentally because of flattened P.S. this article of mine - pnpm's strictness helps to avoid silly bugs, even started a discussion in a npm chat about making --global-style the default |
Beta Was this translation helpful? Give feedback.
-
pnpm's strictness is a big advantage, I agree on that. But to be honest, peerDependencies in its current state are useless.. there is no point in using them neither in npm nor in pnpm. Real pluggable packages, don't exist (at least I have never seen one). Now to the problem I want to solve: webpack. When working with peerDeps, I have to type out all peerDeps, then there is no point in using a dependency collection in the first place. The current (untested) workaround is to manually resolve the package dir link with I think it would be totally sufficient to only auto install peerDeps on top level, after all other packages are installed, and only warn on failure, so they are treated like citizen second class - this would still allow the usage of pluggable packages, as normal dependencies would override them. If you insist on the current way, this issue can be closed. |
Beta Was this translation helpful? Give feedback.
-
I think the way people do it is they have their peerDependencies as devDependencies as well. That is kinda what you are asking for (installing it only on top level). Including them as devDependencies is not good?
Are you sure? We'll have to file an issue at webpack in that case. We had issues with CRA and with latest webpack they are gone, so I assumed they have fixed it. I know they have an option to turn off resolve symlink, but it is on by default. A package symlink is resolved to its real location and pnpm does create a node_modules folder one directory up the package's real location. Have you tried with
Maybe I named it incorrectly but babel, eslint use peer dependencies to work with their plugins. And they work with pnpm. (Except one issue with eslint #739) |
Beta Was this translation helpful? Give feedback.
-
By the way, we have this issue at webpack webpack/webpack#5087 |
Beta Was this translation helpful? Give feedback.
-
I have tackled this issue extensively. Its very tricky in general - lots of edge cases, especially when You can just use webpack's |
Beta Was this translation helpful? Give feedback.
-
I have tested it with webpack@3. This worked with peerDep at npm@1-2 and with normal dep with npm@3-5 and yarn |
Beta Was this translation helpful? Give feedback.
-
In package A you should refer to package B using require.resolve, or you
can add package A's node modules dir to require.modules
Do you have a sample project I can look at?
…On Wed 28. Jun 2017 at 6:20 PM, Paul Pflugradt ***@***.***> wrote:
I have tested it with ***@***.***
There is no way I can ship package A somehow connected to B so that
webpack can resolve B
This worked with peerDep at ***@***.*** and with normal dep with ***@***.*** and
yarn
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#827 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AARLRa1XLns8OpxqYH4NdMTXhCESXs0Xks5sIn1jgaJpZM4OFG7M>
.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
With webpack everything is possible! I'm not 100% on what your trying to do
but if you can show me a sample project I'm pretty sure I can resolve it.
Relying on flat node modules will be problematic if there are multiple
versions of the dep in the tree too. But I'd have to see code.
…On Wed 28. Jun 2017 at 6:59 PM, Paul Pflugradt ***@***.***> wrote:
In package A you should refer to package B using require.resolve
This won't work for other dependencies than js. Stylesheets for example.
or you can add package A's node modules dir to require.modules
This will work, but then the installation instructions of A get very ugly,
I really want to prevent that.
I also could order the user to also install B, also ugly in my eyes.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#827 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AARLRZ2k5-MwO6G-OSY8irkSAo0K4IGEks5sIoaGgaJpZM4OFG7M>
.
|
Beta Was this translation helpful? Give feedback.
-
I have ceri-materialize which is basically a wrapper around materialize-css with a few added stylesheets. // sass
@import "~ceri-materialize/color"; //works
// works in npm due to flattened tree
// but not in pnpm
@import "~materialize-css/sass/components/variables";
// no way to resolve the dependency:
@import "~ceri-materialize/../materialize-css/sass/components/variables"; //doesn't work
@import "~ceri-materialize/node-modules/materialize-css/sass/components/variables"; //doesn't work for example code you can clone ceri-tooltip and run thanks for your time! |
Beta Was this translation helpful? Give feedback.
-
Okay reproduced:
|
Beta Was this translation helpful? Give feedback.
-
So in You should depend directly on pnpm will never support accessing a module from a module that doesn't depend on it. However, you can configure webpack with a custom loader resolver. Modify |
Beta Was this translation helpful? Give feedback.
-
If there is ever another version of @zkochan We should have a tag we use for all the issues relating to flat modules. And we should have a standard FAQ page to point people to explaining why relying on flat modules is bad. |
Beta Was this translation helpful? Give feedback.
-
@vjpr lets create a pnpm-manifesto repo with listings of all the things pnpm is meant to be And of course I am always happy to extend the FAQ section |
Beta Was this translation helpful? Give feedback.
-
I think it all breaks down to my impression, that if a package A has a peerDep B and I install A I should also have access to B. (same problem in #829)
Currently peerDep really means optionalDep, but with a warning if it isn't installed.. (making that optionality obsolete 😑) |
Beta Was this translation helpful? Give feedback.
-
I noticed we can use function readPackage(pkg) {
pkg.dependencies = {
...pkg.peerDependencies,
...pkg.dependencies,
}
pkg.peerDependencies = {};
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
}; I'm using more opinionated version of this. |
Beta Was this translation helpful? Give feedback.
-
Can we have add a parameter like |
Beta Was this translation helpful? Give feedback.
-
It looks like Example:
|
Beta Was this translation helpful? Give feedback.
-
this should be the default behavior. breaking with NPMv7 is just @zkochan's power trip ... team red is leaving the chat edit: 🖕 to all the haters. |
Beta Was this translation helpful? Give feedback.
-
what is wrong with you? |
Beta Was this translation helpful? Give feedback.
-
If you want this feature so bad, make a PR and make it opt-in. If most will vote to make it the default, then we'll make it the default. I don't understand what is your problem with me. |
Beta Was this translation helpful? Give feedback.
-
So apparently not everyone is happy about how this changed in npm: npm/feedback#610 |
Beta Was this translation helpful? Give feedback.
-
Someone is happy (see Why not just following NPM's decision and avoiding unpleasant surprises that people switching to PNPM get because of this incompatibility? |
Beta Was this translation helpful? Give feedback.
-
In v6.26 a new setting was released: auto-install-peers. If you set this option to |
Beta Was this translation helpful? Give feedback.
-
@zkochan, how is the setting My environment: ❯ node --version && npm --version && pnpm --version && cat ~/.npmrc
v16.13.1
8.1.2
6.26.1
package-lock=true NPMThis is the scenario with ❯ npm i requirejs-babel7
added 3 packages, and audited 4 packages in 4s
found 0 vulnerabilities The package with its two peer dependencies was installed, PNPM - Forced Command LineAlthough the forced command line was not what I was looking for, nothing else worked. Forcing usage of unknown config settings works, although the syntax is not what I expect for a documented setting and there are two other problems: ❯ pnpm i requirejs-babel7 --config.auto-install-peers=true
Already up-to-date
WARN Issues with peer dependencies found
.
└─┬ requirejs-babel7
├── ✕ missing peer @babel/standalone@7.x
└── ✕ missing peer babel-plugin-transform-modules-requirejs-babel@0.x
Peer dependencies that should be installed:
@babel/standalone@7.x
babel-plugin-transform-modules-requirejs-babel@0.x
Installing missing peer dependencies
Progress: resolved 2, reused 1, downloaded 0, added 0, done And although it works, it performs two unexpected actions:
PNPM - Command LineThe argument ❯ pnpm i requirejs-babel7 --auto-install-peers=true
ERROR ERROR Unknown option: 'auto-install-peers'
Did you mean 'unsafe-perm'? Use "--config.unknown=value" to force an unknown option.
For help, run: pnpm help add PNPM - NPMRC ConfigThe config ❯ pnpm config set auto-install-peers=true
❯ pnpm config get auto-install-peers
true
❯ pnpm i requirejs-babel7
Packages: +1
+
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: /Users/ferdipr/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm
dependencies:
+ requirejs-babel7 1.1.0
WARN Issues with peer dependencies found
.
└─┬ requirejs-babel7
├── ✕ missing peer @babel/standalone@7.x
└── ✕ missing peer babel-plugin-transform-modules-requirejs-babel@0.x
Peer dependencies that should be installed:
@babel/standalone@7.x
babel-plugin-transform-modules-requirejs-babel@0.x
Progress: resolved 1, reused 1, downloaded 0, added 1, done PNPM - package.jsonAlthough I did not want to modify the local project, I was so desperate that I tried something crazy in "pnpm": {
"autoInstallPeers": true,
"peerDependencyIssues": {
"autoInstallPeers": true
}
} This had no effect on the peer dependency handling. |
Beta Was this translation helpful? Give feedback.
-
I set auto-install-peers = true, but don't work example is https://docusaurus.io/docs/typescript-support pnpx create-docusaurus@latest my-website classic --typescript
pnpm install --save-dev typescript @docusaurus/module-type-aliases @tsconfig/docusaurus |
Beta Was this translation helpful? Give feedback.
-
I also can't get |
Beta Was this translation helpful? Give feedback.
-
Does this not work with dev dependencies, the Running pnpm version 7.0.1 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
This was implemented! Update pnpm to v7.1.3 or newer and set
auto-install-peers
totrue
.The original purpose of peerDependencies with npm@1 was, that a package can define packages to install alongside.
With the flattened dependencies tree with npm@3 this functionally was redundant, as ALL dependencies are getting installed alongside, as a result the automatic installation of peer dependencies was disabled and there is no real use-case for defining peer dependencies anymore..
With pnpm this isn't the case, as you choose to use a npm@1 like package dep tree, you should also use the npm@1 peerDep behaviour and install them automatically.
Say package A needs B,C,D as peerDep I would have to call:
pnpm install A B C D # instead of npm install A
if a peerDep conflicts with a normal dep, the normal dep should win and a warning should get printed..
(also peerDeps should get installed when linked)
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions