Resolving 'process.env' TypeError During windows-build-tools Installation
Problem Statement
When running npm install --global windows-build-tools on Node.js v18.12.0 (or newer), you encounter this fatal error:
TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor.
This occurs because the windows-build-tools package has compatibility issues with newer Node.js versions (v18+). The installer fails during environment validation, preventing installation of required build tools like Visual Studio Build Tools or Python.
Recommended Solutions
Optimal Solution: Install Build Tools via Official Installer
RECOMMENDED
The current preferred approach avoids windows-build-tools entirely
- Uninstall your current Node.js version
- Download the Official Node.js Windows Installer for your desired version
- During installation:
- Check the box for "Tools for Native Modules"
(Enables automatic installation of C++ build tools)
- Check the box for "Tools for Native Modules"
- After Node.js installation completes:
- A new PowerShell window will automatically install necessary build tools
- Verify installation by compiling native modules or installing packages that require compilation
Alternative Method: Manual VS Build Tools Installation
If you prefer manual control:
- Download Visual Studio Build Tools
- In the installer:
- Select "Desktop development with C++" workload
- Include all default components
- Run in administrative terminal after installation:powershell
npm config set msvs_version 2022 - Test native module compilation
Compatibility Workaround: Downgrade Node.js
LEGACY APPROACH
Only use if you cannot use the recommended methods
- Uninstall Node.js v18+
- Install Node.js v17.9.1
- Open temporary directory:
- Press
Win + R, type%temp%, press Enter
- Press
- Create file
dd_client_.log.txtwith content:txtClosing installer. Return code: 3010. - Run in administrative terminal:bash
npm install --global windows-build-tools - After successful installation, carefully upgrade Node.js if needed
Key Technical Insights
Why This Happens
The windows-build-tools package uses an outdate approach to configure process.env properties that conflicts with newer security restrictions in Node.js v18+.
Modern Alternatives
The Node.js installer now integrates with Microsoft's build tools chain, providing:
- Automatic installation of required components
- Better version management
- First-party support from Microsoft
Maintenance Status
Windows-build-tools has had no significant updates since 2020 and should be avoided for new setups.
Verification Steps
After successful setup:
- Install a native module package:bash
npm install bcrypt - Verify compilation:bash(No errors = successful setup)
node -e "require('bcrypt')"
Maintenance Note
For long-term projects, use the integrated toolchain method to ensure compatibility with future Node.js releases.
Summary of Approaches
| Method | When to Use | Maintenance Level |
|---|---|---|
| Official Node.js Installer | ✅ New setups, most reliable approach | First-party |
| Manual VS Build Tools Install | When you need control over VS components | Supported |
| Node v17 + Temp File Workaround | 🛑 Only for legacy applications | Unmaintained |