Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  181] [ 2]  / answers: 1 / hits: 6744  / 5 Years ago, mon, august 5, 2019, 12:00:00

I have the following question. Currently I want to build a NPM module which this expected behaviour:



Once I've installed it, all its dependencies would work perfectly in the project only import them.



First of all, what I have is this:



enter



I have my-module project as the dependencies modules I want with that specific versions.



On the other hand I have a project which imports it as we can see.



Inside my project I want to write, for example, the following code and finally run it:



import {Calendar} from 'primereact/calendar';


How could I deal with this trouble?



Thanks in advance!



EDIT: My project's package.json is this



{
name: my-project,
version: 0.0.0,
description: ,
main: index.js,
scripts: {
dev: next src,
build: next build src,
start: next start src
},
license: ISC,
dependencies: {
next: ^9.0.3,
react: ^16.8.6,
react-dom: ^16.8.6,
@ascope/my-module: file://../my-module
}
}


Also my-module's package.json:



{
name: my-module,
version: 0.0.1,
main: index.js,
scripts: {
test: exit 1
},
license: ISC,
bundledDependencies: [
primereact,
rxjs
],
dependencies: {
primereact: ^3.1.8,
rxjs: ^6.5.2
},
peerDependencies: {
primereact: ^3.1.8,
rxjs: ^6.5.2
}
}

More From » npm

 Answers
0

Both packages will need the primereact dependency, when you do an install on the top level package it will move the primereact dependency up, assuming there's a version that can satisfy both dependencies.



Have a look at NPM install algorithm




For this package{dep} structure: A{B,C}, B{C}, C{D}, this algorithm
produces:




A
+-- B
+-- C
+-- D



That is, the dependency from B to C is satisfied by the fact that A
already caused C to be installed at a higher level. D is still
installed at the top level because nothing conflicts with it.








For A{B,C}, B{C,D@1}, C{D@2}, this algorithm produces:




A
+-- B
+-- C
`-- D@2
+-- D@1



Because B’s D@1 will be installed in the top level, C now has to
install D@2 privately for itself. This algorithm is deterministic, but
different trees may be produced if two dependencies are requested for
installation in a different order.




You can also run npm dedupe


[#6679] Friday, August 2, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrellhunterm

Total Points: 82
Total Questions: 109
Total Answers: 98

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
terrellhunterm questions
;