TL;DR;
Try running npm update to update the esbuild package dependencies in your package-lock.json file.
Background
First, you should not remove your package-lock.json file. It is an important file with a purpose and should remain version controlled (https://nodejs.dev/learn/the-package-lock-json-file).
I believe the issue is that vite uses esbuild. esbuild lists a number of optionalDependencies:
"optionalDependencies": {
"esbuild-android-64": "0.14.32",
"esbuild-android-arm64": "0.14.32",
"esbuild-darwin-64": "0.14.32",
"esbuild-darwin-arm64": "0.14.32",
"esbuild-freebsd-64": "0.14.32",
// and so on...
}
Each of these dependencies lists a CPU and OS it depends on, like in your error:
"node_modules/esbuild-windows-64": {
"version": "0.14.32",
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.32.tgz",
"integrity": "sha512-+p4MuRZekVChAeueT1Y9LGkxrT5x7YYJxYE8ZOTcEfeUUN43vktSn6hUNsvxzzATrSgq5QqRdllkVBxWZg7KqQ==",
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=12"
}
}
For some reason, up to a certain version of esbuild these dependencies cause Netlify to think these platforms are required and thus it fails because its container is running Linux. Updating to at least version 0.14.36 fixed the problem for me, there's an ever newer version out than that at the time of this writing. You will still see warnings such as
2:59:00 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/esbuild-windows-64):
2:59:00 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
but the build will no longer fail.