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

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

Open
henrikvtcodes opened this issue Jun 9, 2024 · 3 comments

Comments

@henrikvtcodes
Copy link

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.

@ascorbic
Copy link
Owner

Oh, I see what's going on here. I'm trying to detect Vercel and Netlify using env vars, but Cloudflare doesn't like that. I'm going to have to think of a way to do that which doesn't need to import node builtins.

@henrikvtcodes
Copy link
Author

henrikvtcodes commented Jun 10, 2024

Would import.meta.env work?

Update: I just modified the base.ts file in node_modules in my own project and that did seem to work. I assume the problem is that it would break in other environments though. I suppose you could take an env object as a parameter and pass it down.

@anastasiiavorobiova
Copy link

Have the same issue here

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

3 participants