Error deploying to Cloudflare Pages
CodeLPrime opened this issue · comments
$ 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:
- Going to your Cloudflare Pages project from the Cloudflare dashboard
- Go to the
Settings
tab - Click on
Functions
in the sidebar - Scroll down to the Compatability flags section
- 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](https://private-user-images.githubusercontent.com/58375830/277556411-9f111a72-426c-4b85-aa65-225e0fb6b30b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3NzkyNjksIm5iZiI6MTcxODc3ODk2OSwicGF0aCI6Ii81ODM3NTgzMC8yNzc1NTY0MTEtOWYxMTFhNzItNDI2Yy00Yjg1LWFhNjUtMjI1ZTBmYjZiMzBiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE5VDA2MzYwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY2OGMxN2U0ZGI5NWQwMDNkMjM5NTYwOWNmNmYzZTQxYjUxYTRkZmI2MmFjMDRkMzY5NmY1MWM0MzJmMzA5ODkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dDKjdVBG0wxVvzLFilf_398325CWomm0AirXZXVomG8)
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?
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 :)