React Vite build fails because of @rollup/rollup-linux-x64-gnu

We have a react application, just moved the build tooling from CRA to Vite, everything works fine locally when we build it but on Neltify it fails.

 > vite build
 node:internal/modules/cjs/loader:1077
   const err = new Error(message);
               ^
 Error: Cannot find module "@rollup/rollup-linux-x64-gnu"
 Require stack:
 - /opt/build/repo/client/node_modules/vite/node_modules/rollup/dist/native.js
     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
     at Module._load (node:internal/modules/cjs/loader:922:27)
     at Module.require (node:internal/modules/cjs/loader:1143:19)
     at require (node:internal/modules/cjs/helpers:119:18)
     at Object.<anonymous> (/opt/build/repo/client/node_modules/vite/node_modules/rollup/dist/native.js:60:48)
     at Module._compile (node:internal/modules/cjs/loader:1256:14)
     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
     at Module.load (node:internal/modules/cjs/loader:1119:32)
     at Module._load (node:internal/modules/cjs/loader:960:12)
     at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29) {
   code: "MODULE_NOT_FOUND",
   requireStack: [
     "/opt/build/repo/client/node_modules/vite/node_modules/rollup/dist/native.js"
   ]
 }

Above is the error message, I’m wondering why it is failing with module not found error @rollup/rollup-linux-x64-gnu.
Do we need to separately install this module? Strangely it works on local system. Tried different node versions and with latest available ubuntu focal image.

It will be helpful if someone help me resolving this? For now, I’m building locally and uploading the build through Netlify CLI.

Site ID: 5afd2c45-b6dc-41b0-90c3-fa0a45c53310

1 Like

I’m facing the same issue. Were you able to resolve this?

1 Like

@smitchell nope, same issue, builds failing

@smitchell I have installed "@rollup/rollup-linux-x64-gnu": "4.6.1", as a dev dependency and deployed.

Can’t install it on a Windows machine because it’s a Linux dependancy. Any ideas on how to fix it on Windows?

@Lucane
I added it to optionalDependencies, like this:

"optionalDependencies": {
    "@rollup/rollup-linux-x64-gnu": "4.6.1"
  },

PS: I registered on this forum to post this, please pay it forward :wink:

6 Likes

Cheers for posting the solution! Didn’t think to add it as an optional dependency.

I actually managed to find an alternative fix by deleting the site on Netlify and creating a new site from the same repo. Doing a “clear cache & deploy” didn’t work, so might be some caching issue on Netlify’s side.

1 Like

oh that’s awesome for you both @Lucane and @JanMisker thanks for sharing your solutions with the community.

1 Like

I have been solving this problem but didn’t get any solution. Does anyone have any idea how to solve it 1?

can you share your build log?

@JanMisker Thank you so much! Adding as an optional dependency is what worked for me.

P.S: Registered first on Netlify and then on this platform to say this. :smile:

2 Likes

I also registered to this forum to say that the optional dependency worked, and I’m not even using Netlify, I’m using AWS. @JanMisker you’re a legend!

2 Likes

The optionalDependencies solution didn’t work for me, but I figured out another one. It may not be applicable to everyone’s projects, but what finally solved this for me was changing this to this in my Dockerfile:

FROM node:20-alpine AS builder
→
FROM node:latest AS builder

thanks for sharing that information with the community.

Thanks for this, it worked for me

Installing @rollup/rollup-linux-x64-gnu as a dev dependency also fixed my issues:


npm install --save-dev @rollup/rollup-linux-x64-gnu
1 Like