Install any skill in seconds. Free to start, no credit card required.
Get Started Free →This skill MUST be used whenever the task involves adding, installing, or upgrading an npm package/library/dependency in this project. Use when the user asks to "add a library", "install <package>", "use <package>", "add a dependency", "bump/upgrade a package", or any change to package.json dependencies. Covers the latest-version policy, esbuild renderer bundling, manual CSS copy, native module rebuilds, and the three build targets.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-15 | ✗→✓ | ▲ Improved | 30% | 0% |
| case-03 | ✗→✓ | ▲ Improved | -4% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 26% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 146% | 0% |
This is an Electron app with three separate build targets (main, preload, renderer) and a few non-obvious bundling rules. Adding a dependency the wrong way silently breaks CSS, native modules, or the renderer bundle. Follow this guide every time.
Always install the newest published version. Never hand-edit package.json to set or downgrade a version.
bashnpm install <pkg>@latest # runtime dependency npm install -D <pkg>@latest # dev / build-only tool (types, bundlers, test libs)
^x.y.z — the repo convention (every dep in package.json uses ^). Leave it as a caret range.package-lock.json is committed and gets updated by the install. Both package.json and package-lock.json are part of your change — stage both.package-lock.json — not yarn, not pnpm)..nvmrc; engines.node is >=18. Run nvm use first if needed.This determines every gotcha that follows.
| Target | Source dirs | How it's built | What's allowed | |--------|-------------|----------------|----------------| | Renderer | src/renderer/** | Bundled by esbuild into one IIFE (build:renderer) | Plain JS/TS deps only. No Node built-ins, no native modules. | | Main | src/main/**, src/shared/** | tsc → CommonJS (dist/main/) | Any Node dep, including native modules. Resolved via require at runtime against node_modules — not bundled. | | Preload | src/preload/**, src/shared/** | tsc → CommonJS (dist/preload/) | Runs in Node/Electron context; same rules as main. |
marked, dompurify, gridstack, @xterm/*) just gets imported in renderer code and esbuild bundles it. Nothing else to do (except CSS — see Step 2)..node binary belongs in main/preload only.esbuild only has the .ts loader configured. It will not bundle any CSS the package ships. If the library needs a stylesheet to work (the way gridstack and @xterm/xterm do):
scripts/copy-assets.js — copy from node_modules/<pkg>/.../file.css to dist/renderer/vendor/<file>.css. Mirror the existing gridstack precedent in that file.<link rel="stylesheet" href="vendor/<file>.css"> to src/renderer/index.html (gridstack/xterm links are already there as examples).If you skip this, the JS bundles fine but the component renders unstyled. (CLAUDE.md documents this: "esbuild has no CSS loader" — gridstack CSS is copied manually.)
.node binaries)Examples already in the repo: better-sqlite3, node-pty.
dependency (never imported from the renderer — main/preload only).npm install triggers the postinstall hook → electron-builder install-app-deps, which rebuilds the .node binary against the pinned Electron ABI. If the module fails to load at runtime ("NODE_MODULE_VERSION mismatch"), re-run npm install and check the postinstall output.asarUnpack in package.json (precedent: **/node_modules/better-sqlite3/**).src/main/platform.ts for the platform-detection helpers.npm install -D @types/<pkg>@latest (precedent: @types/better-sqlite3, @types/dompurify, @types/picomatch).There is no hot reload — every change needs a rebuild.
bashnpm run build # must pass: tsc main + tsc preload + esbuild renderer + copy-assets npm test # Vitest suite
Then confirm the dependency actually works end to end:
npm start, and visually confirm the feature renders and styles load.electron-builder packages only dist/main/**, dist/preload/**, dist/renderer/**:
dist/renderer/index.js.node_modules at runtime, so they must be in dependencies (not devDependencies). Keep build-only tooling (bundlers, types, test libs) in devDependencies.Do:
npm install <pkg>@latest, leave the caret range, commit package.json + package-lock.json.<link> for any styled renderer library.npm run build and npm test before declaring done.Don't:
package.json.scripts/copy-assets.js step for CSS (esbuild won't bundle it).devDependencies or assume it works without the postinstall rebuild.$ARGUMENTS
Other measured skills in the registry, with their headline benchmark lift.