This guide will walk you through building nut.js from source on Windows, including building the native dependencies.
windows-build-tools npm package is deprecated and no longer works. You must install Visual Studio Build Tools manually by downloading the installer from Microsoft's website.
-
Visual Studio 2022 Build Tools (Required):
- Go to Visual Studio Downloads
- Scroll down to "Tools for Visual Studio" section
- Download "Build Tools for Visual Studio 2022" (not Visual Studio 2026 or newer)
- Run the downloaded installer (
.exefile) - During installation, select the "Desktop development with C++" workload
- Ensure "Windows 10/11 SDK" is selected (usually selected by default)
- Click "Install" and wait for the installation to complete (this may take 10-30 minutes)
Note: Visual Studio 2026 and newer versions are not yet recognized by node-gyp/cmake-js. You must use Visual Studio 2022 Build Tools.
-
Python (for node-gyp):
- Download from python.org
- During installation, check "Add Python to PATH"
- Python 3.8 or higher is recommended
-
Verify Visual Studio 2022 Installation:
- After installation completes, verify it was successful by running this command in a regular Command Prompt:
where devenv - If the command returns a path (e.g.,
C:\Program Files\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\devenv.exe), the installation was successful. - If the command returns nothing, the installation may have failed or the tools are not in your PATH.
- After installation completes, verify it was successful by running this command in a regular Command Prompt:
-
⚠️ Important: Use Developer Command Prompt for VS 2022- All subsequent commands in this guide must be run in the "Developer Command Prompt for VS 2022"
- You can find it by searching for "Developer Command Prompt" in the Start menu
- Look for "Developer Command Prompt for VS 2022" (not VS 2026 or newer)
- This sets up all necessary environment variables (PATH, VCINSTALLDIR, etc.) that are required for building native Node.js modules
- Do not use regular Command Prompt or PowerShell - the build will fail without these environment variables
Ensure you have Node.js installed (version 16 or higher for nut.js, 10.15.3+ for libnut-core):
node --version
npm --versionIf not installed, download and install from nodejs.org.
REM Configure npm to use a directory in your home folder
mkdir "%APPDATA%\npm-global" 2>nul
npm config set prefix "%APPDATA%\npm-global"
REM Add to your PATH (you may need to add this manually to your system PATH)
setx PATH "%PATH%;%APPDATA%\npm-global"Note: After running setx, you may need to close and reopen your command prompt for PATH changes to take effect.
nut.js uses pnpm as its package manager. Install it:
npm install -g pnpm@8.15.2pnpm -vIf you're running Windows 10 N and want to use ImageFinder plugins, install the Media Feature Pack.
Option: Automated Installation Script
If you prefer an automated installation, you can use the install-windows.bat script which automates all the steps below. The script:
- Checks prerequisites
- Clones repositories
- Builds libnut-core
- Automatically edits package.json files
- Installs dependencies and compiles
To use the script, open "Developer Command Prompt for VS 2022" and run:
install-windows.batManual Installation (Step-by-Step)
If you prefer to follow the steps manually or need more control, continue with the steps below.
Open the Developer Command Prompt for VS 2022 and run:
REM Create a directory for the projects
mkdir nutjs-build
cd nutjs-build
REM Clone libnut-core (the native dependency)
git clone https://github.com/nut-tree/libnut-core.git
cd libnut-coreImportant: Make sure you're in the "Developer Command Prompt for VS 2022" (not VS 2026). This ensures all necessary environment variables are set correctly.
REM Install npm dependencies
npm install
REM Patch the package name for your platform (Windows)
set CI=true
npm run patch
REM Build the release version
npm run build:releaseThis will compile the native C/C++ code and create a .node module. The build output will be in build\Release\.
Note: The first build may take several minutes as it compiles all native dependencies.
REM Go back to your build directory
cd ..
REM Clone nut.js
git clone https://github.com/nut-tree/nut.js.git
cd nut.jsEdit nut.js\providers\libnut\package.json and change the Windows dependency:
Find this line:
"@nut-tree/libnut-win32": "2.7.1",Replace with:
"@nut-tree/libnut-win32": "file:../../../libnut-core",Also update the peer dependency (change ^3 to ^4 to match workspace version):
Find:
"peerDependencies": {
"@nut-tree/nut-js": "^3"
}Replace with:
"peerDependencies": {
"@nut-tree/nut-js": "^4"
}Make macOS/Linux packages optional (move them to optionalDependencies):
Find:
"dependencies": {
"@nut-tree/libnut-darwin": "2.7.1",
"@nut-tree/libnut-linux": "2.7.1",
"@nut-tree/libnut-win32": "file:../../../libnut-core"
}Replace with:
"dependencies": {
"@nut-tree/libnut-win32": "file:../../../libnut-core"
},
"optionalDependencies": {
"@nut-tree/libnut-darwin": "2.7.1",
"@nut-tree/libnut-linux": "2.7.1"
}Edit nut.js\examples\screen-test\package.json to make premium packages optional:
Find:
"dependencies": {
"@nut-tree/nut-js": "workspace:*",
"@nut-tree/nl-matcher": "2.2.0"
}Replace with:
"dependencies": {
"@nut-tree/nut-js": "workspace:*"
},
"optionalDependencies": {
"@nut-tree/nl-matcher": "2.2.0"
}Update peer dependencies in nut.js\providers\clipboardy\package.json:
Find:
"peerDependencies": {
"@nut-tree/nut-js": "^3"
}Replace with:
"peerDependencies": {
"@nut-tree/nut-js": "^4"
}REM Remove old lock file to regenerate with workspace packages (in nutjs directory)
del pnpm-lock.yaml 2>nul
REM Install all dependencies
pnpm install
REM Compile all TypeScript packages
pnpm run compileTo verify the installation worked:
REM Check that the compiled packages exist
dir core\nut.js\dist
dir providers\libnut\distIf both directories exist and contain files, the installation was successful.
From the nut.js package directory, create a global link (in Developer Command Prompt for VS 2022):
cd nutjs-build\nut.js\core\nut.js
pnpm link --globalNavigate to your project directory and link the package (in Developer Command Prompt for VS 2022):
cd C:\path\to\your\project
pnpm link --global @nut-tree/nut-jsIn your project's package.json:
{
"dependencies": {
"@nut-tree/nut-js": "link:"
}
}Then run pnpm install or npm install in your project. You got yourself a free, self-built nutjs, go nuts!!!
Error: "unknown version 'undefined' found" or "could not find a version of Visual Studio 2017 or newer to use"
This error occurs when you have Visual Studio 2026 or newer installed. node-gyp/cmake-js does not yet recognize these newer versions.
Solution:
- Install Visual Studio 2022 Build Tools (not 2026 or newer)
- Use the "Developer Command Prompt for VS 2022" (not VS 2026)
- If you have both versions installed, you can create a
.npmrcfile in thelibnut-coredirectory with:msvs_version=2022
Error: "MSBuild.exe not found"
- Ensure Visual Studio 2022 Build Tools are installed
- You must run commands from "Developer Command Prompt for VS 2022" - regular Command Prompt will not work
- Verify installation by running in Developer Command Prompt:
where devenv - If
where devenvreturns a path, VS 2022 is installed correctly - If it returns nothing, reinstall Visual Studio 2022 Build Tools
Error: "Python not found"
- Install Python from python.org
- During installation, ensure "Add Python to PATH" is checked
- Verify installation by running:
python --version
Error: "node-gyp rebuild failed" or "cmake-js rebuild failed"
- Ensure you have Visual Studio 2022 Build Tools installed (not 2026 or newer)
- Ensure "Desktop development with C++" workload is installed
- Ensure "Windows 10/11 SDK" is selected
- Run from "Developer Command Prompt for VS 2022"
- If using VS 2026, install VS 2022 Build Tools alongside it
Windows uses backslashes in paths. If you encounter path issues:
- Use forward slashes in package.json file paths (npm/pnpm handle this)
- Or use double backslashes:
file:..\\..\\..\\libnut-core
If you see errors about premium packages (@nut-tree/libnut-darwin, @nut-tree/libnut-linux, @nut-tree/nl-matcher, etc.), ensure you've moved them to optionalDependencies as described in Step 4 and Step 5.
If you encounter "path too long" errors:
- Enable long paths in Windows (requires admin, run Command Prompt as Administrator):
Then restart your computer.
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
- Or build in a shorter path (e.g.,
C:\nutjsinstead of deep nested paths)
Some antivirus software may interfere with the build process:
- Temporarily disable real-time scanning during build
- Add your build directory to antivirus exclusions