Skip to content

Commit 3988998

Browse files
authored
feat: add vscode extension packaging blog (#216)
1 parent 085711f commit 3988998

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
61.2 KB
Loading
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: "Packaging a VS Code Extension Using pnpm and VSCE"
3+
slug: "packaging-a-vs-code-extension-using-pnpm-and-vsce"
4+
date: 2025-08-31
5+
authors: ["Ansh Arora"]
6+
tags: ["Makim", "Automation", "VSCode", "pnpm", "esbuild"]
7+
categories: ["Packaging", "Node", "Extensions"]
8+
description: |
9+
A step-by-step guide to packaging and publishing VS Code extensions with pnpm and vsce,
10+
covering how to avoid dependency resolution issues.
11+
thumbnail: "/header.png"
12+
template: "blog-post.html"
13+
---
14+
15+
# Packaging a VS Code Extension Using pnpm and VSCE
16+
17+
VS Code’s `vsce` tool doesn't play nicely with `pnpm` out of the box; here’s a
18+
proven workaround using bundling and the `--no-dependencies` flag to get things
19+
running smoothly.
20+
21+
---
22+
23+
## Why pnpm + vsce can be problematic
24+
25+
`vsce` relies on `npm list --production --parseable --depth=99999`, which fails
26+
under pnpm's symlink-based dependency management, often throwing
27+
`npm ERR! missing:` errors.
28+
([github.com](https://github.com/microsoft/vscode-vsce/issues/421),
29+
[daydreamer-riri.me](https://daydreamer-riri.me/posts/compatibility-issues-between-vsce-and-pnpm/))
30+
31+
---
32+
33+
## Solution Overview
34+
35+
1. **Bundle your extension** using a bundler such as **esbuild** or **Webpack**
36+
2. **Use `--no-dependencies`** when running `vsce package` and `vsce publish`
37+
38+
Because all dependencies are bundled, `vsce` no longer needs to resolve them
39+
from `node_modules`.
40+
41+
---
42+
43+
## Step-by-Step Setup
44+
45+
### 1. Install Tools
46+
47+
```bash
48+
pnpm add -D @vscode/vsce esbuild
49+
```
50+
51+
@vscode/vsce` is the CLI for packaging and publishing VSCode extensions. Recent
52+
versions (e.g., v3.6.0) support npm (≥6) and Yarn (1.x), but don't officially
53+
support pnpm.
54+
55+
### 2\. Configure `package.json`
56+
57+
Scripts Add build and packaging commands: jsonc Copy code
58+
59+
```json
60+
{
61+
"scripts": {
62+
"vscode:prepublish": "pnpm run bundle",
63+
"bundle": "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --minify",
64+
"package": "pnpm vsce package --no-dependencies",
65+
"publish": "pnpm vsce publish --no-dependencies"
66+
}
67+
}
68+
```
69+
70+
- `vscode:prepublish`: runs before packaging; bundles source using esbuild
71+
- `bundle`: compiles `extension.ts` into `out/main.js` and excludes the `vscode`
72+
module
73+
- `package` / `publish`: calls VSCE via pnpm, skipping dependency resolution
74+
75+
### 3\. Why It Works
76+
77+
By bundling dependencies manually, `vsce` doesn’t need to resolve them during
78+
packaging or publishing. The `--no-dependencies` option avoids pnpm’s symlink
79+
issues entirely.
80+
81+
## Sample `package.json` Snippet
82+
83+
```json
84+
{
85+
"devDependencies": {
86+
"@vscode/vsce": "^3.6.0",
87+
"esbuild": "^0.XX.X"
88+
},
89+
"scripts": {
90+
"vscode:prepublish": "pnpm run bundle",
91+
"bundle": "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --minify",
92+
"package": "pnpm vsce package --no-dependencies",
93+
"publish": "pnpm vsce publish --no-dependencies"
94+
}
95+
}
96+
```
97+
98+
### **Wrap-Up**
99+
100+
Using **pnpm** with VS Code extensions involves a few extra steps because `vsce`
101+
doesn’t support pnpm’s dependency structure directly. The ideal workflow: _
102+
**Bundle your extension first**, then _ **Use `--no-dependencies`** to package
103+
and publish safely.

0 commit comments

Comments
 (0)