Failed Deployment

Similar to this post: https://discord.com/channels/595317990191398933/1236032759923736668 I have tried deploying in vain, the deploy succeeds when using npm run deploy but ultimately fails with no logs or indication of the is causing the problem. The deployment id for the last deploy is 554ebc67-f85b-433f-8e65-9a9a53ea0259
25 Replies
Nolan
Nolanβ€’8mo ago
Hey there! It looks like we've got a edge_deployment_failed error with the following output.
deploy_worker_failed:Uncaught Error: Dynamic require of "node:crypto" is not supported at functionsWorker-0.4400651895596901.js:12:9 at functionsWorker-0.4400651895596901.js:72396:19 in ../node_modules/@remix-run/node/dist/sessions/fileStorage.js at functionsWorker-0.4400651895596901.js:18:50 in __require2 at functionsWorker-0.4400651895596901.js:72898:23 in ../node_modules/@remix-run/node/dist/index.js at functionsWorker-0.4400651895596901.js:18:50 in __require2 at functionsWorker-0.4400651895596901.js:74025:27 in ../build/server/index.js at functionsWorker-0.4400651895596901.js:15:56 in __init at functionsWorker-0.4400651895596901.js:74194:5 in [[path]].ts at functionsWorker-0.4400651895596901.js:15:56 in __init at functionsWorker-0.4400651895596901.js:74204:5 in ../.wrangler/tmp/pages-NNfL6Q/functionsRoutes-0.3802553210814601.mjs
deploy_worker_failed:Uncaught Error: Dynamic require of "node:crypto" is not supported at functionsWorker-0.4400651895596901.js:12:9 at functionsWorker-0.4400651895596901.js:72396:19 in ../node_modules/@remix-run/node/dist/sessions/fileStorage.js at functionsWorker-0.4400651895596901.js:18:50 in __require2 at functionsWorker-0.4400651895596901.js:72898:23 in ../node_modules/@remix-run/node/dist/index.js at functionsWorker-0.4400651895596901.js:18:50 in __require2 at functionsWorker-0.4400651895596901.js:74025:27 in ../build/server/index.js at functionsWorker-0.4400651895596901.js:15:56 in __init at functionsWorker-0.4400651895596901.js:74194:5 in [[path]].ts at functionsWorker-0.4400651895596901.js:15:56 in __init at functionsWorker-0.4400651895596901.js:74204:5 in ../.wrangler/tmp/pages-NNfL6Q/functionsRoutes-0.3802553210814601.mjs
blindChicken
blindChickenOPβ€’8mo ago
How do I fix this? I have added the nodejs_compat compatibility flags?
Walshy
Walshyβ€’8mo ago
you'll want that require to be an import, esbuild doesn't support dynamic requires. Sadly that looks to be in remix's code
blindChicken
blindChickenOPβ€’8mo ago
The require is from a third party package, dotenv. Which I am using to get the keys for my CF-Turnstile widget
Walshy
Walshyβ€’8mo ago
../node_modules/@remix-run/node/dist/sessions/fileStorage.js
looks like it's in remix not dotenv but either way, it looks like this wouldn't work anyway as it's trying to use files (fs) can you switch to a different session storage? they have a built-in createWorkersKVSessionStorage but you can also use like cookie
blindChicken
blindChickenOPβ€’8mo ago
I'm guessing that this is being cause by Turnstile likely for the proof of space mechanism it uses?
Walshy
Walshyβ€’8mo ago
turnstile isn't using remix nor sessions remix is a web framework Seems like you're using it + auth sessions backed by file storage
blindChicken
blindChickenOPβ€’8mo ago
I'm not using any of that. I used CF template for remix. The website is super simple, an info page and a contact form. The contact form has Turnstile on it. I'm guessing that because of SSR, it is causing Turnstile to do stuff on the server which should only be done on the client.
Walshy
Walshyβ€’8mo ago
This has nothing to do with turnstile, it's just the way remix is setup
blindChicken
blindChickenOPβ€’8mo ago
Note that, in order for it to deploy in my console with wrangler I needed to go and manually add the node: prefix to the require in the dotenv, cookiesignature and `stream-slice packages.
Walshy
Walshyβ€’8mo ago
sounds like a lot of node dependencies haha Not sure if dotenv works in Workers since that usually loads from .env - no fs in Workers. You should have those in .dev.vars or wrangler.toml
blindChicken
blindChickenOPβ€’8mo ago
✘ [ERROR] Could not resolve "os"

../node_modules/dotenv/lib/main.js:3:19:
3 β”‚ const os = require('os')
β•΅ ~~~~

The package "os" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "os"

../node_modules/dotenv/lib/main.js:3:19:
3 β”‚ const os = require('os')
β•΅ ~~~~

The package "os" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project and make sure to prefix the module name with "node:" to enable Node.js compatibility.
Walshy
Walshyβ€’8mo ago
yeah ^ You'll have to de-nodeify this project
blindChicken
blindChickenOPβ€’8mo ago
That is likely the problem. I was basing myself on this post: https://www.jacobparis.com/content/remix-cloudflare-pages
Jacob Paris
Deploy a new Remix app to Cloudflare Pages
Cloudflare doesn't use Node.js. Use wrangler as your dev server. Use .dev.vars instead of .env. Make sure you set up wrangler.toml correctly.
blindChicken
blindChickenOPβ€’8mo ago
How? Are there an resources?
Walshy
Walshyβ€’8mo ago
ah ok, that's trying to use dotenv in a node env there (vite dev server)
blindChicken
blindChickenOPβ€’8mo ago
I'm using the wrangler dev server. So I'm basically mixing the two things up?
Walshy
Walshyβ€’8mo ago
I'm not sure Remix's official guidance these days, that guide is using vite dev to build the files and then wrangler dev to just handle running them
blindChicken
blindChickenOPβ€’8mo ago
This is my current build script:
"deploy": "remix vite:build && wrangler pages deploy ./build/client --commit-dirty",
"deploy": "remix vite:build && wrangler pages deploy ./build/client --commit-dirty",
I'm clearly using vite to build, which I guess is wrong. So how should this look?
Walshy
Walshyβ€’8mo ago
Seems fine to me, interesting you needed to use dotenv, are you importing it in your code not just vite config?
blindChicken
blindChickenOPβ€’8mo ago
I don't know that I "needed to use dotenv" as I said I was blindly following the blog. So I replaced dotenv by using context in my loader , action functions in remix, and that provides me access to the vars. I have to clean out all the node stuff and try to deploy again. I removed dotenv and reinstalled the packages and then tried to re-deploy and I'm left with:
✘ [ERROR] Build failed with 2 errors:

../node_modules/cookie-signature/index.js:5:21: ERROR: Could not resolve "crypto"
../node_modules/stream-slice/index.js:3:24: ERROR: Could not resolve "stream"
✘ [ERROR] Build failed with 2 errors:

../node_modules/cookie-signature/index.js:5:21: ERROR: Could not resolve "crypto"
../node_modules/stream-slice/index.js:3:24: ERROR: Could not resolve "stream"
Walshy
Walshyβ€’8mo ago
yeah so can you also avoid these two packages haha
blindChicken
blindChickenOPβ€’8mo ago
I found the problem. I was re-using code from another project and it was importing from @remix-run/node. Fixed it to be from @remix-run/cloudflare and it solved the issue. It's working now! Thanks for your helpπŸ™
ABSK
ABSKβ€’8mo ago
Does someone has the fix for SvelteKit for this problem. I am still getting Could not resolve "crypto" using the cloudflare adapter.
dangoldin
dangoldinβ€’4mo ago
Thank you! Just had the exact same issue and was struggling to figure out what the problem was
Want results from more Discord servers?
Add your server