unpic-img icon indicating copy to clipboard operation
unpic-img copied to clipboard

[Astro] Vite bundling problem when using the cloudflare server adapter

Open henrikvtcodes opened this issue 8 months ago • 2 comments

Describe the bug When the Cloudflare server adapter is used with the Unpic image service in Astro, a build error occurs:

[commonjs--resolver] [plugin vite:resolve] Cannot bundle Node.js built-in "node:process" imported from "node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected]_/node_modules/@unpic/astro/src/service/base.ts". Consider disabling ssr.noExternal or remove the built-in dependency.
  Stack trace:
    at getRollupError (file:///Users/henrikvt/Desktop/Code/projects/unpic-ssr-bug-repro/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
    at Object.error (file:///Users/henrikvt/Desktop/Code/projects/unpic-ssr-bug-repro/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19589:20)
    at Object.handler (file:///Users/henrikvt/Desktop/Code/projects/unpic-ssr-bug-repro/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-DEPSZ3SS.js:68935:19)
    at async PluginDriver.hookFirstAndGetPlugin (file:///Users/henrikvt/Desktop/Code/projects/unpic-ssr-bug-repro/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
    at async ModuleLoader.resolveId (file:///Users/henrikvt/Desktop/Code/projects/unpic-ssr-bug-repro/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18758:15)

I have tried adding @unpic/astro/node:process to ssr.noExternal, tried setting it as an empty array, all to no avail.

To Reproduce Here is a reproduction of the bug: https://github.com/henrikvtcodes/unpic-cf-ssr-bug-repro

Steps to reproduce the behavior:

  1. Create a new astro project
  2. Add the Cloudflare Pages adapter
  3. Install and add unpic as the image service
  4. Build the project and see the error

Expected behavior I expected that the project would build with no problems.

Environment

  • OS: macOS 14
  • Browser: Firefox 126
  • Node v20.13.1 see above reproduction for versions of astro, unpic, etc

Additional context This problem occurred locally as well as in the Cloudflare deploy process.

henrikvtcodes avatar Jun 09 '24 19:06 henrikvtcodes