Joshua's Docs - Notes and Tips on Using yalc for Local Packages

Resources:

How to Use

Here are the commands I needed to learn ASAP:

  • Initial Run:
    • yalc publish in source package, yalc add {packageName} where testing / in consumer
    • Use yalc link {packageName} for symlink version, which does not modify package.json
    • Use --dev for devDependency, with either add or link
  • Updating:
    • Run yalc publish --push (or just yalc push) in source package to distribute updates wherever it is used
    • If files seem to get stuck, you can try:
      • yalc push --replace
      • In testing: yalc remove {packageName} && yalc add {packageName}

Fun Tips

  • yalc publish --files runs faster for me than npm publish --dry-run (this is to get a tarball / publish preview of what files would end up on NPM)

Watching for Changes

Currently, Yalc does not have a built-in way to watch for changes and relink / republish on source code updates.

The --changed flag with publish or push is to avoid redundant relinking when files have not changed. It does not watch anything.

However, there are some workarounds. The one I have personally tried is using nodemon as the watcher.

For example, here is how you could set up nodemon to run yalc push with a TypeScript package that compiles to /dist:

{
	"scripts": {
		"watch": "nodemon -e js,ts --ignore dist --exec \"tsc --sourceMap && yalc push --changed\""
	}
}

Troubleshooting

  • Issues using bin, command not found, etc.
    • Did you make sure to run yarn or npm install after linking a new package that contributes bin entries? You can also use --npm or --yarn with yalc publish commands to trigger this.
  • Issues with Cannot find module ____
    • Try deleting your yarn.lock or package-lock.json file and then running yarn or npm install again
    • Check your lockfile (and/or node_modules) to verify the dependency is getting pulled in
  • Issues with UnhandledPromiseRejectionWarning: Error: EEXIST: file already exists, symlink ...
    • You might have a corrupted node_modules setup; try rm -rf node_modules combined with yalc remove and yalc add for a full reset
  • Yalc doesn't seem to be respecting package.json files option
    • Make sure you haven't mixed up ./{dir} and /{dir} - you should be using the second version. This is true for npm as well.
Markdown Source Last Updated:
Mon Dec 06 2021 21:43:57 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Wed Jul 29 2020 19:21:17 GMT+0000 (Coordinated Universal Time)
© 2024 Joshua Tzucker, Built with Gatsby
Feedback