Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter-node : sharp included in bundle #13464

Open
bienoubien-studio opened this issue Feb 14, 2025 · 2 comments
Open

adapter-node : sharp included in bundle #13464

bienoubien-studio opened this issue Feb 14, 2025 · 2 comments

Comments

@bienoubien-studio
Copy link

Describe the bug

When installing a package that has sharp as a dependency, then bundling sveltekit project with adapter-node.
Get error running the server :

Error: Could not load the "sharp" module using the darwin-arm64 runtime
undefined: Could not dynamically require "../src/build/Release/sharp-darwin-arm64.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "../src/build/Release/sharp-wasm32.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "@img/sharp-darwin-arm64/sharp.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.
undefined: Could not dynamically require "@img/sharp-wasm32/sharp.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.

After some search I've found that sharp is included in the bundle.
If installing sharp in the sveltekit project directly, sharp is deduped and not include in the bundle.

in vite.config.ts (try everything):

  optimizeDeps: { exclude: ["sharp"] },
  ssr: {
    external: ["sharp"],
  },
  build: {
    rollupOptions: {
      external: ["sharp"],
    },
  }

It's probably not specific to sharp.
As I am making a package for sveltekit that rely on sharp, I'd like that devs who install my package doesn't have to explicitly install sharp to make it work. Or am I missing something ?

Reproduction

git clone [email protected]:bienoubien-studio/adapter-node-sharp.git adapter-node-sharp
cd adapter-node-sharp
cd package 
npm install
npm pack
cd ../app
npm install
npm run build
grep -r "sharp" build # looks like it's included
npm preview # work
node build # fail with error

Logs

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M2
    Memory: 70.72 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v22.8.0/bin/npm
    pnpm: 10.0.0 - /opt/homebrew/bin/pnpm
    bun: 1.1.17 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 132.1.74.51
    Chrome: 132.0.6834.83
    Safari: 18.0
  npmPackages:
    @sveltejs/adapter-auto: ^4.0.0 => 4.0.0 
    @sveltejs/adapter-node: ^5.2.12 => 5.2.12 
    @sveltejs/kit: ^2.16.0 => 2.17.1 
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3 
    svelte: ^5.0.0 => 5.20.0 
    vite: ^6.0.0 => 6.1.0

Severity

annoyance

Additional Information

No response

@bienoubien-studio bienoubien-studio changed the title adapter-node includes sharp in bundle even if set to external when dependency of another one... adapter-node : sharp includes in bundled Feb 14, 2025
@bienoubien-studio bienoubien-studio changed the title adapter-node : sharp includes in bundled adapter-node : sharp included in bundled Feb 14, 2025
@bienoubien-studio bienoubien-studio changed the title adapter-node : sharp included in bundled adapter-node : sharp included in bundle Feb 14, 2025
@dummdidumm
Copy link
Member

adapter-node bundles everything in devDependencies and externalizes packages in dependencies. You should be able to use that to not bundle sharp - but people will have to npm ci --omit dev in their deployment environment
https://svelte.dev/docs/kit/adapter-node#Deploying

@bienoubien-studio
Copy link
Author

externalizes packages in dependencies

Actually it doesn't as sharp is listed as dependency but bundled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants