Published on

How to install local dependency package in NPM Workspaces

Authors

Let's say you've two packages and you're maintaining them using npm's workspaces feature

And want to use package-a inside package-b

Here's how to do it:

# Initialize npm project
npm init -y

# Setup new packages using workspaces
npm init -w ./packages/a

# when it asks for the package name give something like -> @example/a

npm init -w ./packages/b
# when it asks for the package name give something like -> @example/b

And to install the local package,

# now, to install dependent package (@example/a in @example/b) do this:

npm i @example/a --workspace=@example/b

Reference

Happy playing-with packages