remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
30.18k stars 2.56k forks source link

Using Cloudflare-only runtime leads to an error during the build step #7461

Open VladimirKras opened 1 year ago

VladimirKras commented 1 year ago

What version of Remix are you using?

2

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

run npx create-remix --template remix-run/remix/templates/cloudflare-pages

Add app/routes/example.tsx that contains

 import { EmailMessage } from "cloudflare:email";
 export const action = () => {
   console.log(EmailMessage);
   return null;
 };

run npm run build

Expected Behavior

Build succeeds on Cloudflare: info built

Actual Behavior

Build fails:

✘ [ERROR] Could not resolve "cloudflare:email"

    app/routes/example.ts:1:29:
      1 │ import { EmailMessage } from "cloudflare:email";
        ╵                              ~~~~~~~~~~~~~~~~~~

  You can mark the path "cloudflare:email" as external to exclude it from the bundle, which will remove this error.
MurmeltierS commented 9 months ago

experiencing this with cloudlfare:sockets

sergiodxa commented 9 months ago

Since the build runs on Node it can't access those packages, try to move them to the Cloudflare server file and use getLoadContext to inject them into your Remix app.