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?
Since
npm link
creates a symlink in the global folder, whilenpm install
is local to the project npm install takes precedence. You can read about npm link here: https://docs.npmjs.com/cli/linkTo avoid this, my suggestion would be to use
npm install <path to local>
and when you need to use the production code usenpm install @organization/module
. This would update your node_modules per code basis. Read about npm install here: https://docs.npmjs.com/cli/installHope this helps :)