DEV Community

Discussion on: How to test your NPM package locally

Collapse
 
jackmellis profile image
Jack

This isn't quite true. Npm is smart enough to resolve common versions of packages so if they both depended on the same major version of react, it would be fine.

This is probably a bad example, though, as 99.9% of the time react would be a peer dependency instead (which completely alleviates this problem and gives the version responsibility to the consumer)

Collapse
 
iamandrewluca profile image
Andrei Luca • Edited

I have to mention again, that this is a specific use case when you use npm link

Unfortunately that's true. NPM is just a package manager, install/uninstall dependencies. Node is the one who resolves dependencies.

nodejs.org/api/modules.html#module...

Smart enough should be the bundler to know what exactly to load.

github.com/iamandrewluca/example-n...

cd npm-calculator
npm install
cd ../npm-calculator-test
npm install
node index.js
Enter fullscreen mode Exit fullscreen mode
17.0.2
16.14.0
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
jackmellis profile image
Jack

I mentioned it in another comment but in my experience, npmjs.com/package/yalc solves all of these kind of issues. It's so useful