Tuesday, 2 October 2018

How to get npm to favor local linked dependency over its published install

I've searched through other questions such as this one, but they all seem to be about a local npm link stopping working for another reason than mine. I assume this is a common use-case issue, so if I'm doing something methodically wrong, I'm more than happy to take suggestions on how I should be doing it.

Principally, I have a private npm module that I'm working on called @organisation/module. When working locally, I'll run npm link on it, and use it within my 'host' project as npm link @organisation/module — this all works great with hot-reloading, etc. I'll also import it as import module from '@organisation/module.

However, since I also want to publish my local changes to npm (as @organisation/module) from time to time, for build testing and production code, I need to run npm install @organisation/module on the host project.

This then seems to break the implicit npm link I set up earlier... I assume mainly because they are the same name, and npm favors an install over a link?

When I want to make live, local changes again, the only way I can currently get it to work is via npm uninstall @organisation/module and then to re-link it.

Is there a way to keep the published module installed (in order to avoid careless mistakes, like forgetting to reinstall it for build testing), but always favour the local, linked instance?

Diagram for ref: Diagram for ref



from How to get npm to favor local linked dependency over its published install

No comments:

Post a Comment