Rebuild broke a working site? Pin versions
You changed one line of text, or you changed nothing at all, and the host ran a fresh build. Now the deploy fails, or worse, it succeeds and the live site is broken: a blank page, a missing component, a form that no longer submits. The code you wrote is the same as last week. What changed is the code you didn't write: the packages and the runtime your site is built with.
The symptom
- A build that passed last week now fails with an error inside a package in
node_modules, not in your own files. - The build passes, but something on the live site behaves differently from the preview, even though the source is identical.
- Re-deploying an old commit that used to work also fails now.
- The error mentions a version, a removed export, "is not a function", or an unsupported Node version.
The giveaway: if an old, known-good commit no longer builds, the problem is not in the commit. It is in what the build downloads.
The cause
Every JavaScript project lists its dependencies in package.json, usually with ranges like ^4.2.0, which means "any 4.x version from 4.2.0 up". A lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock or bun.lockb) records the exact versions that were installed, so every build gets the same ones. Things go wrong when:
- The lockfile is missing or ignored. Without it, each fresh install picks the newest version inside the range. A package author ships a release with a breaking change or a bug, and your next build quietly picks it up.
- Two lockfiles disagree. A project exported from one tool and opened in another can end up with both
package-lock.jsonandbun.lockb. The host picks one package manager, and it may not be the one whose lockfile is current. - The Node version drifts. Hosts change their default Node version over time. A build that ran on one major version may fail or behave differently on the next if nothing in the project pins it.
- A dependency was added with "latest". AI builders sometimes install a package without a version range, or with a very loose one, so the version on the host can differ from the one in the preview.
Step-by-step diagnosis
- Read the build log, not just the result. Find the first error line. Note which package it comes from and the file path it points to.
- Compare installed versions. Most build logs print the package manager and Node version near the top. Compare them with the last successful build's log, which most hosts keep in the deploy history.
- Check for a lockfile in the repository. Open the repo on GitHub or in your editor. If there is no lockfile, or there are two from different tools, you have found a likely cause.
- Rebuild locally from a clean slate. Delete
node_modules, run a clean install (npm ciuses the lockfile exactly), then build. If it fails the same way, look at what that package changed in its latest release notes. - Test the old version. Pin the suspect package to the previous version you know worked and rebuild. If the error disappears, you have confirmed it.
Fixes per builder or host
Lovable and Bolt
Both can sync to GitHub. Make sure exactly one lockfile is committed and it matches the package manager your host uses. Ask the builder to pin the package that broke to a specific version in package.json, and check the diff before you accept it so it doesn't upgrade other packages at the same time.
Replit
Check the Nix and Node settings in the .replit and replit.nix files, and keep the lockfile committed. Deployments build from the same files, so a pinned version in the workspace carries over.
v0 and Cursor projects on Vercel or Netlify
Set the Node version explicitly: an engines field in package.json, a .nvmrc file, or the Node version setting in the project dashboard. Both hosts detect the package manager from the lockfile, so delete the ones you don't use. In Cursor, review any dependency change before committing.
How to verify
- Trigger a fresh build with the build cache cleared, so nothing old is reused.
- Confirm the log shows the Node version and package manager you expect.
- Open the live site in a private window and walk through the main flow: load, sign in, submit a form, reach the page that broke.
- Re-deploy once more without changes. A pinned project should produce the same result every time.
Prevention
- Always commit one lockfile, and only one.
- Pin the Node version in the project, not just in the host's defaults.
- Upgrade dependencies on purpose, one at a time, and test the preview before publishing.
- Check the live site from outside after every deploy, because a build can pass while the page it produces is broken.
Pinning versions makes every build repeatable, and a quick outside check tells you within minutes if one still slips through.
