If two local dependencies depends on the same npm dependency they will have two separate installs

(Afreakk) #1

What I Wanted to Do

I wanted for instance to have APP depend on two local modules (module-a and module-b), and have both local modules depend on a npm package (jsonschema for instance).
Have module-b produce an instance of jsonschema.ValidationError, and have module-a be able to receive said instance and check if it is an instanceof jsonschema.ValidationError.

What Happened Instead

module-a does not recognize the instance as an instance of jsonschema.ValidationError, because module-a and module-b has separate installations of npm package jsonschema.

Reproduction Steps

example code doing what i explained above:
git clone --single-branch --branch local-dependencies-have-different-installs-of-same-lib https://github.com/afreakk/npm-error-example
cd npm-error-example
cd app && npm install && node index.js

Details

cd app && npm install && node index.js will produce:

moduleA thinks validationErrorInstance is instanceof validationError: false
moduleB thinks validationErrorInstance is instanceof validationError: true

Platform Info

Tested with npm version 6.9.0
0 Likes