SvelteKit project throw an error during Vercel build

Hello folks :wave:

I’m building two different projects in Svelte with SvelteKit and I’m facing the same error in both project deployments in Vercel.

error during build:
Error [ERR_REQUIRE_ESM]: require() of ES Module /vercel/path0/node_modules/string-width/index.js from /vercel/path0/node_modules/wide-align/align.js not supported.
Instead change the require of index.js in /vercel/path0/node_modules/wide-align/align.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/vercel/path0/node_modules/wide-align/align.js:2:19)
error: script "build" exited with code 1
Error: Command "bun run build" exited with 1

It’s interesting to note that this error is only thrown when the build is triggered by a push to my GitHub repository. If I retry the deployment manually, it passes each time.

Thx in advance for your help!

Hey @mardi66! I wasn’t able to replicate this issue with a SvelteKit starter project. Do you have a public repo or minimal reproducible example that we can use to debug this together?

Hey @amyegan! Thx for your reply
Unfortunately, both repositories are private…

I can give you my dependencies if it helps

"devDependencies": {
    "@sveltejs/adapter-auto": "^3.0.0",
    "@sveltejs/kit": "^2.0.0",
    "@sveltejs/vite-plugin-svelte": "^4.0.0",
    "@types/eslint": "^9.6.0",
    "autoprefixer": "^10.4.20",
    "clsx": "^2.1.1",
    "eslint": "^9.7.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-svelte": "^2.36.0",
    "globals": "^15.0.0",
    "prettier": "^3.3.2",
    "prettier-plugin-svelte": "^3.2.6",
    "prettier-plugin-tailwindcss": "^0.6.5",
    "svelte": "^5.0.0",
    "svelte-check": "^4.0.0",
    "tailwindcss": "^3.4.9",
    "typescript": "^5.0.0",
    "typescript-eslint": "^8.0.0",
    "vite": "^5.0.3"
  },
  "dependencies": {
    "gsap": "^3.12.5"
  }```

Both projects are just at their beginning, they're nothing more than an index page and the added packages in it.

I know SvelteKit is designed to work with ESM, so it’s important to make sure everything in the project uses that same syntax. It looks like something in the project uses wide-align and the require() on this line is throwing the error.

I asked v0 for more ideas. You can find the full chat here: https://v0.dev/chat/SxFxCJlDS7g

Please give those suggestions a try and let me know how it goes :smile:

1 Like

Thx again for your help!

Do you have any idea why the build succeeds when it’s retried manually?

I don’t know for sure, but it sounds like a Build cache issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.