Build fails when `@sveltejs/enhanced-img` was installed on ARM CPU but the current environment is x86
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
I'm trying to deploy a project with @sveltejs/enhanced-img:0.3.0 to Cloudflare.
I ran npm i -D @sveltejs/enhanced-img on a Mac with an ARM-based architecture.
When I deploy to Cloudflare (their architecture is x86) and I get the following error during the SvelteKit build process:
16:11:36.861 | npm ERR! command failed
-- | --
16:11:36.866 | npm ERR! command sh -c node postinstall.js
16:11:36.872 | npm ERR! Error: Cannot find module @rollup/rollup-linux-x64-gnu. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
16:11:36.874 | npm ERR! at requireWithFriendlyError (/opt/buildhome/repo/node_modules/rollup/dist/native.js:59:9)
16:11:36.880 | npm ERR! at Object.<anonymous> (/opt/buildhome/repo/node_modules/rollup/dist/native.js:68:76)
16:11:36.885 | npm ERR! ... 3 lines matching cause stack trace ...
16:11:36.889 | npm ERR! at Module._load (node:internal/modules/cjs/loader:938:12)
16:11:36.895 | npm ERR! at cjsLoader (node:internal/modules/esm/translators:284:17)
16:11:36.900 | npm ERR! at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:234:7)
16:11:36.906 | npm ERR! at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
16:11:36.910 | npm ERR! at async ModuleLoader.import (node:internal/modules/esm/loader:316:24) {
16:11:36.916 | npm ERR! [cause]: Error: Cannot find module '@rollup/rollup-linux-x64-gnu'
The workaround I found is manually setting the x86 variant as an optional dependency in package.json.
Also, it's not just @rollup/rollup-linux-x64-gnu, it's these 3:
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.0.0",
"@cloudflare/workerd-linux-64": "1.20240701.0",
"@img/sharp-linux-x64": "0.33.4"
},
Reproduction
https://github.com/fmaclen/cloudflare-adapter-dependencies/tree/enhanced-img-issue
Note: the .node-version was intentionally set because of this other issue related to Cloudflare:
https://github.com/sveltejs/kit/issues/12464
Logs
No response
System Info
System:
OS: macOS 14.5
CPU: (16) arm64 Apple M3
Memory: 14.90 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - /usr/local/bin/node
npm: 10.1.0 - /usr/local/bin/npm
Browsers:
Chrome: 124.0.6367.208
Safari: 17.5
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.2.2
@sveltejs/adapter-cloudflare: ^4.6.1 => 4.6.1
@sveltejs/enhanced-img: ^0.3.0 => 0.3.0
@sveltejs/kit: ^2.0.0 => 2.5.18
@sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1
svelte: ^4.2.7 => 4.2.18
vite: ^5.0.3 => 5.3.3
Severity
serious, but I can work around it
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction branch and its package.json, then compare the ARM installation with the x86 Cloudflare build and the reported postinstall.js failure. Check the dependency handling around @rollup/rollup-linux-x64-gnu, @cloudflare/workerd-linux-64, and @img/sharp-linux-x64; done means the Cloudflare build succeeds without manually adding architecture-specific optional dependencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- build-system, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100