cyco130 / vite-plugin-cjs-interop

Vite plugin to unwrap default imports from CJS dependencies during SSR
MIT License
72 stars 6 forks source link

Wrangler / Cloudflare Error when deploying to Cloudflare Pages #47

Open AdrianHouseholder opened 2 months ago

AdrianHouseholder commented 2 months ago

I am using Cloudflare to host my Remix.js app, and even though the project works perfectly locally, and before adding Apollo, when I try to deploy it to Cloudflare, I get the following errors:

Captura

I understand that the cjsInterop1 import naming convention is basically what the plugin does underneath, but it looks like Wrangler doesn't like it.

The reason why I needed this plugin was because I am using Apollo to consume my Graphql API, and it considers the library to be CommonJS. The plugin made the project work flawlessly locally, but unfortunately, I've run into this error once I try to deploy it.

I ran into this issue here, but does not work in my case: https://community.cloudflare.com/t/wrangler-throws-error-with-package-type-module-and-webpack-config-js/339507

Any ideas? Thank you in advanced!

cyco130 commented 2 months ago

Hi!

Have you tried disabling the plugin for the deployment build (maybe using an env var or something)?

The problem that this plugin solves is specific to Node, it doesn't apply to Cloudflare's workerd runtime. As far as I know, Cloudflare uses ESBuild to bundle the worker and ESBuild can fix CJS interop issues better than this plugin.

cyco130 commented 2 weeks ago

Closing due to inactivity.