Bright Labs

npm install prerender fails with "Failed to locate: CL.exe" on Windows: what it means and the fix

You ran npm install for prerender on Windows, and the build stopped at "Failed to locate: CL.exe". CL.exe is Microsoft's C++ compiler, and the install couldn't find it. The fix is to install the Visual C++ build tools, then run npm install again from a Developer Command Prompt. And if all you wanted was the middleware for your app, check first whether you need this build at all.

Microsoft's docs describe cl.exe plainly: "Use the compiler (cl.exe) to compile and link source code files into apps, libraries, and DLLs." node-gyp, per its README, is "a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js." No compiler on the machine, no build.

Check which prerender package you actually need

This one is easy to miss. prerender-node describes itself as "Express middleware for prerendering javascript-rendered pages on the fly for SEO". That's the piece that goes in your app.

The prerender-node README says: "We host a Prerender server at prerender.io so that you can work on more important things." It also says the middleware "will default to the service already deployed by prerender.io". You can point it at a different service with the PRERENDER_SERVICE_URL environment variable or the prerenderServiceUrl option.

So if your goal is "my React or Vue site should serve HTML to crawlers through a hosted service", the package to install in your app is the middleware:

From the prerender-node README
npm install prerender-node --save

There's one catch. The same README says: "If you're testing locally, you'll need to run the prerender server locally so that it has access to your server." If that's your case, or you want to run the server yourself, keep reading and fix the compiler.

If you'd rather not run the server at all, here's one option. We make RenderSwap, a hosted prerender service: your prerender-node middleware stays, and you swap the service URL and the token for the ones from your RenderSwap account. The Free plan covers 1 verified domain and 500 fresh renders or 1 browser hour a month, whichever comes first, with no card and no email to sign up. It renders only your own public pages, on domains you've verified, so it won't help with a localhost test.

Install the Visual C++ build tools

node-gyp's own README covers this. The quick route uses Chocolatey and installs Python and the Visual C++ workload in one go:

From the node-gyp README, On Windows section
choco install python visualstudio2026-workload-vctools -y

For the manual route, the README says that for Visual Studio 2019 or later, you use the `Desktop development with C++` workload. For anything older, it says to install Visual Studio Build Tools with the Visual C++ build tools option. Microsoft's page adds that if you want only the command-line toolset, you can download the Build Tools for Visual Studio.

If you've seen advice to install windows-build-tools, check its repository page first. It now says: "This repository was archived by the owner on Sep 11, 2021. It is now read-only." Use the routes above instead.

Run npm install from a Developer Command Prompt

Installing the tools isn't always the end of it. Microsoft's page says: "The tools require several environment variables to be set. These variables add the tools to the path and set the locations of include files, library files, and SDKs."

If the install now gets past the compile step, you're done. If it fails with a different error, read the first error line in the log, not the last one.

When node-gyp still can't find Visual Studio

If the tools are installed and node-gyp still doesn't pick them up, the README suggests installing a PowerShell module:

From the node-gyp README
Install-Module VSSetup -Scope CurrentUser

In the README's words: "This will make Visual Studio detection logic use a more flexible and accessible method, avoiding PowerShell's `ConstrainedLanguage` mode."

You can also tell node-gyp which Visual Studio to use. Its --msvs_version option is described as "Set Visual Studio version (Windows only)". For one older toolset you need it: "Auto-detection fails for Visual C++ Build Tools 2015, so `--msvs_version=2015`" needs to be added. The README notes it's not needed when run by npm as configured in its install steps.

From the node-gyp README
node-gyp configure --msvs_version=2015

Quick reference: which fix for which setup

What to do about "Failed to locate: CL.exe" depending on what you're building
Your situationWhat to do
You only need the middleware in your Express appInstall prerender-node and point it at a hosted service
You want to run the prerender server yourselfInstall the Desktop development with C++ workload or Build Tools for Visual Studio
Tools installed, error still thereRe-run npm install from a fresh Developer Command Prompt
node-gyp can't detect Visual StudioInstall the VSSetup PowerShell module, or pass --msvs_version
Windows on ARMAdd the ARM64 compiler and ATL components

Sources

Questions

Do I need the full Visual Studio IDE to fix "Failed to locate: CL.exe"?

No. Microsoft says that if you want only the command-line toolset, you can download the Build Tools for Visual Studio. node-gyp's README also gives a Chocolatey command that installs Python and the Visual C++ workload.

I installed the C++ tools and still get the error. Why?

Check your terminal first. Microsoft says the tools require several environment variables, and these variables add the tools to the path. Open a new Developer Command Prompt and run npm install again from there.

Is windows-build-tools still the way to install the compiler?

Its repository was archived by the owner on Sep 11, 2021 and is read-only. The same page says the official Node.js for Windows installer can now install the required tools, and node-gyp's README lists the Visual Studio routes.

Do I need the prerender package to use prerender-node with a hosted service?

Not going by the prerender-node README. prerender-node is the Express middleware, and it defaults to the service already deployed by prerender.io. You can set PRERENDER_SERVICE_URL or prerenderServiceUrl to use a different service. The README says that if you're testing locally, you'll need to run the prerender server locally so that it has access to your server.

Related