How to resolve `node:crypto` error during Sveltekit deploy

Run npm run preview to preview your production build locally.
12:28:16.327
12:28:16.327 > Using @sveltejs/adapter-cloudflare
12:28:16.697 ✔ done
12:28:16.914 Finished
12:28:16.914 Found _worker.js in output directory. Uploading.
12:28:18.231 ✘ [ERROR] 1 error(s) and 0 warning(s) when compiling Worker.
12:28:18.232
12:28:18.232
12:28:18.235
12:28:18.236 ✘ [ERROR] Could not resolve "node:crypto"
12:28:18.236
12:28:18.236 _worker.js:64950:26:
12:28:18.236 64950 │ import { webcrypto } from "node:crypto";
12:28:18.236~~~~~~~~~~~~~
12:28:18.237
12:28:18.237 The package "node:crypto" wasn't found on the file system but is built into node.
12:28:18.237 Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
12:28:18.237
12:28:18.237
12:28:18.238 ✘ [ERROR] Build failed with 1 error:
12:28:18.238
12:28:18.239 _worker.js:64950:26: ERROR: Could not resolve "node:crypto"
12:28:18.239
12:28:18.239
12:28:18.251 Failed building Pages Functions.
12:28:19.652 Failed: generating Pages Functions failed. Check the logs above for more information. If this continues for an unknown reason, contact support: https://cfl.re/3WgEyrH
Run npm run preview to preview your production build locally.
12:28:16.327
12:28:16.327 > Using @sveltejs/adapter-cloudflare
12:28:16.697 ✔ done
12:28:16.914 Finished
12:28:16.914 Found _worker.js in output directory. Uploading.
12:28:18.231 ✘ [ERROR] 1 error(s) and 0 warning(s) when compiling Worker.
12:28:18.232
12:28:18.232
12:28:18.235
12:28:18.236 ✘ [ERROR] Could not resolve "node:crypto"
12:28:18.236
12:28:18.236 _worker.js:64950:26:
12:28:18.236 64950 │ import { webcrypto } from "node:crypto";
12:28:18.236~~~~~~~~~~~~~
12:28:18.237
12:28:18.237 The package "node:crypto" wasn't found on the file system but is built into node.
12:28:18.237 Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
12:28:18.237
12:28:18.237
12:28:18.238 ✘ [ERROR] Build failed with 1 error:
12:28:18.238
12:28:18.239 _worker.js:64950:26: ERROR: Could not resolve "node:crypto"
12:28:18.239
12:28:18.239
12:28:18.251 Failed building Pages Functions.
12:28:19.652 Failed: generating Pages Functions failed. Check the logs above for more information. If this continues for an unknown reason, contact support: https://cfl.re/3WgEyrH
name = "--project_name"
account_id = "--my_id"

compatibility_flags = [ "nodejs_compat" ]
name = "--project_name"
account_id = "--my_id"

compatibility_flags = [ "nodejs_compat" ]
I've tried creating a wrangler.toml file with the node compat config but it doesn't change the outcome.
3 Replies
Kite
Kite6mo ago
bump
_Pear
_Pear6mo ago
is this a local build or in CI? is node available where you're building? It should work, i have the same stack and im using node:crypto
Kite
Kite6mo ago
Solution: Add the node_compat flag from within Cloudflares dashboard panel, see screenshot for reference or follow the link: https://developers.cloudflare.com/workers/runtime-apis/nodejs/
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
No description
Want results from more Discord servers?
Add your server