What’s the proper method for deploying a Node.js app with a locally modified npm dependency?

While working with the jsdom library in a Node.js project, I encountered an issue that I resolved by manually editing files in the node_modules/jsdom/lib/jsdom/level2/languages directory. Now that I need to deploy my application to a different server, I’m unsure how to handle this modified package. Generally, what procedures or best practices should be followed when dealing with npm dependencies that have been altered?

In my experience, the best approach is to use a tool like patch-package to manage the changes to your npm dependency. This allows you to keep your modifications in a separate patch file that can be applied after a fresh install. This method minimizes the risk of conflicts when updating the package in the future and provides a clear record of what was changed. Alternatively, for a more permanent solution, consider forking the dependency and updating your package.json to point to your repository. This ensures consistency across environments and eases future maintenance.

In my experience, after modifying an npm dependency locally, the best approach is to incorporate your changes into a dedicated repository. Forking the package and referencing your fork in package.json has worked well for me, especially when the modifications become complex. This method maintains traceability and better version control compared to using inline patches. While patch-package can be a quick solution for minor fixes, a forked repository ensures consistency and simplifies collaboration on further improvements or bug fixes during deployment.