I'm developing a project using Next.js 15.5.4 inside an Electron.js application, with the following stack:
- React.js
- Tailwind CSS
- SQLite
On Windows 11, running npm run build (or next build) consistently fails with:
⨯ ENOENT: no such file or directory, scandir 'C:\Users\<username>\<project-folder>\node_modules\@img\sharp-darwin-arm64'
I have tried several approaches:
- Deleting
node_modulesandpackage-lock.json - Cleaning the npm cache (
npm cache clean --force) - Installing Sharp explicitly for Windows:
npm install sharp --ignore-scripts=false --platform=win32 --arch=x64
- Setting
images: { unoptimized: true }innext.config.js - Adding Sharp as a webpack external:
config.externals.push({ sharp: 'commonjs sharp' });
- Removing
.nextand rebuilding
However, the error still occurs. It seems that Next.js attempts to scan the macOS Sharp binary (sharp-darwin-arm64) from @img, even though I'm on Windows 11 and never developed this project on a Mac.
My questions:
- Why does Next.js attempt to scan a Mac-specific Sharp binary on Windows in an Electron environment?
- Is there a way to fully ignore or bypass
@img/sharp-darwin-arm64on Windows? - Are there known workarounds for Electron + Next.js projects where Sharp binaries are platform-specific?