This is my package json file and I'm getting this error?
▲ [WARNING] The version of Wrangler you are using is now out-of-date.
Please update to the latest version to prevent critical errors.
Run npm install --save-dev wrangler@4
to update to the latest version.
After installation, run Wrangler with npx wrangler
.
✘ [ERROR] Build failed with 2 errors:
✘ [ERROR] Could not resolve "crypto"
../node_modules/.pnpm/cookie-signature@1.2.2/node_modules/cookie-signature/index.js:5:21:
5 │ var crypto = require('crypto');
╵ ~~~~~~~~
The package "crypto" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "stream"
../node_modules/.pnpm/stream-slice@0.1.2/node_modules/stream-slice/index.js:3:24:
3 │ var Transform = require('stream').Transform;
╵ ~~~~~~~~
The package "stream" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Failed to build Functions at ./functions.
🪵 Logs were written to "/Users/apple/Library/Preferences/.wrangler/logs/wrangler-2025-03-24_21-55-21_759.log"
Based on the error messages, you're encountering issues with Node.js built-in modules (crypto
and stream
) that aren't being resolved properly in your Vite build for Cloudflare Pages deployment.
This is a common issue when using Remix with Vite for Cloudflare Pages 123. The error suggests using platform: 'node'
in your Vite configuration to resolve these issues.
Here's how to fix it:
vite.config.ts
file to include the proper configuration:code
npm install --save-dev wrangler@4
npm install --save-dev node-stdlib-browser
Then update your Vite config to use these polyfills:
code
These configuration changes should help resolve the Node.js built-in module errors you're encountering when building for Cloudflare Pages.