Install A NPM Package Under An Alias

As more and more NPM packages are being released the available names of packages are dwindling. You might want to name your module something but a package you installed might be causing a naming collision. Thanks to NPM aliasing feature you can install packages under an aliased name and name your local modules whatever you want!

Say you have a local module named store but you also want to use the battle tested local storage wrapper store in your application. You might want to alias your install of store:

npm install local-store@npm:store

This will appear in your package.json as:

  "dependencies": {
    "local-store": "npm:store@^2.0.12",

You can then reference it in your file by the alias:

import * as localStore from 'local-store'

You’re then free to use the name store however you wish! Pretty cool, right?!

The release announcement can be found here.

Instagram Post