Installs npm/yarn packages locally without symlink, also in npm 5. Exactly the same as your production installation, no compromises.
npm install -g install-local
or for occasional use, without installation
$ npx install-local
You can use install-local from command line or programmatically.
Usage:$ install-local # 1$ install-local [options] <directory>[ <directory>] # 2$ install-local --target-siblings # 3
Installs a package from the filesystem into the current directory.
-h, --help: Output this help
-S, --save: Saved packages will appear in your package.json under "localDependencies"
-T, --target-siblings: Instead of installing into this package, this package gets installed into sibling packages which depend on this package by putting it in the "localDependencies". Useful in a lerna style monorepo.
install-localInstall the "localDependencies" of your current package
install-local ..Install the package located in the parent folder into the current directory.
install-local --save ../sibling ../sibling2Install the packages in 2 sibling directories into the current directory.
install-local --helpPrint this help
See Programmatically to see how use
install-local from node.
Why installing packages locally? There are a number of use cases.
- You want to test if the installation of your package results in expected behavior (test your .npmignore file, etc)
- You want to install a package locally in a lernajs-style monorepo
- You just want to test a fork of a dependency, after building it locally.
Well... nothing is wrong with npm link. It's just not covering all use cases.
For example, if your using typescript and you
npm link a dependency from a parent directory, you might end up with infinite ts source files, resulting in an out-of-memory error:
An other reason is with
npm link your not testing if your package actually installs correctly. You might have files in there that will not be there after installation.
Can't i use
npm i file:?
You could use
npm install file:.. versions of npm prior to version 5. It installed the package locally. Since version 5, the functionality changed to
npm link instead. More info here: https://github.com/npm/npm/pull/15900
How to guarantee a production-like install
Typings are included for all your TypeScript programmers out there
const cli execute Options progress LocalInstaller = ;
Use the CLI programmatically
Execute the cli functions with the
cli function. It returns a promise:
Or a slightly cleaner api:
Install dependencies locally
LocalInstaller to install local dependencies into multiple directories.
const localInstaller =/*1*/ '.': '../sibling1' '../sibling2'/*2*/ '../dependant': '.';;localInstaller;
- This will install packages located in the directories "sibling1" and "sibling2" next to the current working directory into the package located in the current working directory (
- This will install the package located in the current working directory (
'.') into the package located in the "dependant" directory located next to the current working directory.
LocalInstall by using an object. The properties of this object are the relative package locations to install into. The array values are the packages to be installed. Use the
install() method to install, returns a promise.
If you want the progress reporting like the CLI has: use
Passing npm env variables
In some cases it might be useful to control the env variables for npm. For example when you want npm to rebuild native node modules against Electron headers. You can do it by passing
const localInstaller ='.': '../sibling'npmEnv: envVar: 'envValue';
Because the value provided for
npmEnv will override the environment of the npm execution, you may want to extend the existing environment so that required values such as
PATH are preserved:
const localInstaller ='.': '../sibling'npmEnv: Object;