LC
bash
Back to Snippets

Patch npm Packages with patch-package

Apply fixes to node_modules packages that persist across installs.

npmpatchnodedependencies
bash
      # 1. Install patch-package
npm install patch-package --save-dev

# 2. Edit the file directly in node_modules
# e.g. node_modules/some-package/dist/index.js

# 3. Create the patch
npx patch-package some-package

# 4. Add postinstall script to package.json

    
json
      {
  "scripts": {
    "postinstall": "patch-package"
  }
}

    

Patches are saved in patches/some-package+1.2.3.patch and auto-applied on npm install.