There are 2 popular options that are widely used for testing packages / libraries in the local environment:
However, Using npm link cause lots of issue when used for testing react component Issue with npm link
Here I will cover guides to setup yalc for testing node packages in local environment
Essentially, we will have two projects that we want to link. The first is our package project and the second one is our main project which will use the package project as Dependency.
For convenience in the term lets call it package-project and main-project
1. Install Yalc as Global Package
npm install -g yalc
OR
yarn global add yalc
2. Publish Package
In the package-project terminal run this command. Your package name will determined based on the project name you set in your package.json
yalc publish
3. Consume Package
If main-project already has package-project as a dependency already. Remove / uninstall that package first.
npm uninstall -S <package_name>
OR
yarn remove <package_name>
Then, In the main-project terminal run this command.
yalc add <package_name>
Package name comes from project name set in
package-projectpackage.json
If package-project has other dependencies used make sure to install those dependencies
npm install
OR
yarn
We’re good to go ! :)
4. Test and making changes
Everytime changes made on package-project rerun
yalc publish
Then, in order to get the effect on main-project run
yalc update <package_name>
5. Some issues that may be encountered
Next Js Project
main-project doesn't get effect from changes made in package-project
Possible workaround - Shut down/terminate main-project dev server - run rm -rf ./next - start dev server back
