netlifyvitevuepress

Vue press 2 deploy to netlify failed with error


I was learning vuepress and tried make a small blog site and decided to deploy it on netlify and it gave me this error. After some googling I found that removing package-lock.json would help but I am facing the same error after deleting package-lock.json

5:57:41 PM: npm ERR! code EBADPLATFORM
5:57:41 PM: npm ERR! notsup Unsupported platform for esbuild-windows-64@0.14.36: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
5:57:41 PM: npm ERR! notsup Valid OS:    win32
5:57:41 PM: npm ERR! notsup Valid Arch:  x64
5:57:41 PM: Creating deploy upload records
5:57:41 PM: npm ERR! notsup Actual OS:   linux

I am using Vite as package manager.It is running fine in local server.


Solution

  • 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: esbuild-windows-64@0.14.49 (node_modules/esbuild-windows-64):
    2:59:00 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for esbuild-windows-64@0.14.49: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
    

    but the build will no longer fail.