sjc5 / hwy

Hwy is a minimalist, Go-based Next.js alternative with nested routing. Works with React or Preact.

Home Page:https://hwy.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error deploying to Cloudflare Pages

CodeLPrime opened this issue · comments

commented
$ npx wrangler pages deploy dist/
No project selected. Would you like to create one or use an existing project?
❯ Create a new project
  Use an existing project
✔ Enter the name of your new project: … hwy-123
✔ Enter the production branch name: … production
✨ Successfully created the 'hwy-123' project.
🌎  Uploading... (17/17)

✨ Success! Uploaded 17 files (1.26 sec)

✘ [ERROR] 2 error(s) and 0 warning(s) when compiling Worker.



✘ [ERROR] Could not resolve "node:path"

    ../node_modules/.pnpm/hwy@0.4.1/node_modules/hwy/dist/index.js:2:18:
      2 │ import path2 from "node:path";~~~~~~~~~~~

  The package "node:path" wasn't found on the file system but is built into node.
  Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Could not resolve "node:process"

    _worker.js:1:20:
      1 │ import process from "node:process";
        ╵                     ~~~~~~~~~~~~~~

  The package "node:process" wasn't found on the file system but is built into node.
  Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Build failed with 2 errors:

  ../node_modules/.pnpm/hwy@0.4.1/node_modules/hwy/dist/index.js:2:18: ERROR: Could not resolve
  "node:path"
  _worker.js:1:20: ERROR: Could not resolve "node:process"

Hi there @CodeLPrime,

Thanks for opening this issue.

We should document this better, but you need to use nodejs_compat mode.

You can enable this in your Cloudflare dashboard by:

  1. Going to your Cloudflare Pages project from the Cloudflare dashboard
  2. Go to the Settings tab
  3. Click on Functions in the sidebar
  4. Scroll down to the Compatability flags section
  5. Add nodejs_compat as a flag for both Production and Preview

The end result should look something like this:

Screenshot 2023-10-24 at 12 19 35 AM

Once that's done, go back to your local project and run:

npm run build && npx wrangler pages deploy dist/

Hopefully eventually they allow this via the CLI, but for now you need to use the Cloudflare Pages dashboard.

Can you give this a try and let me know if it works, @CodeLPrime?

commented

Hello, @sjc5:

Cloudflare Pages deployment (preview + production) works after enabling the nodejs_compat compatibility flag.

I appreciate the detailed instructions and the screenshot.

Thank you for all that you do.

Cheers,

L

P.S. I am interested in helping out with documentation. Feel free to email me at username @ Gmail.

Awesome, thanks @CodeLPrime!

Regarding docs, that would be great. Very soon I'm going to re-work the docs project to be much easier to both read and contribute to. I'll try to remember to give you a ping when the structure is in a little better place / more long-term. And of course, PRs welcome any time in the meantime :)