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.
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.
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!
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