Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Covers adding or upgrading npm dependencies in an Electron app: latest-version policy, esbuild renderer bundling, and native modules.
Use this skill ↓14% 82%+68 ptsof test cases passed
Passed 18 of 22 test cases with the skill, and 3 of 22 without it.
3 of 3 safety checks passed
Not used yet
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.
npm 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.)
Next to this one in the catalogue, plus more from the same author.