VSCode Source Code Study (Part 1): Running Locally
Recently, I am going to learn the source code of vscode. The first step is to run it.
The steps I followed are mostly based on the official contribution documentation:
Here are some key steps distilled from there. For accuracy, please refer to the official documentation.
Since VSCode's compilation involves using node-gyp, which can be troublesome to install on Windows, my plan is to run it in WSL (Windows Subsystem for Linux).
Ensure you have Git, Node.js, Yarn, Python, and C++ toolchain installed in your WSL:
- Node.js, x64, version
>=18.15.x and <19
- Yarn 1, version
>=1.10.1 and <2, follow the installation guide
- Python (required for node-gyp; refer to node-gyp readme for supported Python versions)
- C/C++ compiler toolchain for your platform:
sudo apt install python3 python-is-python3 libsecret-1-dev libxss1 libx11-dev libxkbfile-dev libasound2 libgtk-3-0 libgdk-pixbuf2.0-0 libnss3 libxtst6 libxi6 libxdamage1 libxcursor1 libxcomposite1 libx11-xcb1 libgbm1
- It's recommended to use VSCode for development. Install VS Code and the Remote - WSL extension.
The first execution might be slow; wait for about 2 minutes, and it should start.
Error while executing
If you encounter errors while running
./scripts/code.sh, it might be due to missing C++ toolchain dependencies. Errors like:
Cannot find module 'ternary-stream'
Error: Cannot find module 'ternary-stream'
Cannot find module 'vscode-gulp-watch'
Error: Cannot find module 'vscode-gulp-watch'
../src/unix/kerberos_gss.h:21:14: fatal error: gssapi/gssapi.h: No such file or directory
Installing C++ dependencies should resolve these issues.
gyp error during yarn dependency installation
Another common error involving node-gyp:
/bin/sh: 1: pkg-config: not found gyp: Call to 'pkg-config --cflags libsecret-1' returned exit status 127 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1
You can try clearing dependencies and reinstalling them:
# Clear dependencies git clean -xfd # Reinstall dependencies yarn
"not a valid Electron app" warning
This is an official warning. Just take note and execute: