The package "crypto" wasn't found on the file system but is built into node.

Solved

The package "crypto" wasn't found on the file system but is built into node.

kiran121
Shopify Partner
5 0 3

I've successfully integrated the Remix-validated form library into my Remix v2 application. However, when attempting to implement the same library in the Shopify Hydrogen framework, I encountered an error stating, '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.'

It's worth noting that this implementation works seamlessly on Hydrogen v1, but issues arise in v2. I'm seeking assistance to address this discrepancy and resolve the 'crypto' package error in the context of Shopify Hydrogen v2. Any guidance or insights would be greatly appreciated.

Accepted Solution (1)

Weaverse
Shopify Partner
73 23 32

This is an accepted solution.

Hello @kiran121 ,
The problem is that Oxygen is using Cloudflare Worker under the hood, and it is not a Node.js environment; it already has a built-in "crypto" module, and the remix-validated-form importing this package will cause the error.
In this case, you can try setting "serverNodeBuiltinsPolyfill" in the remix config like follows:

serverNodeBuiltinsPolyfill: {
modules: {
crypto: true, // Provide a JSPM polyfill
},
},


Reference: https://remix.run/docs/en/main/file-conventions/remix-config#servernodebuiltinspolyfill

Helping merchants build super unique, high-performance storefronts using Weaverse + Hydrogen.
Looking for Development & Agency partners.
If you find the answer helpful, give it a thumbs up!
Our App: Theme Customizer for Shopify Hydrogen
Join our Weaverse + Hydrogen community: Weaverse Community

View solution in original post

Replies 2 (2)

Weaverse
Shopify Partner
73 23 32

This is an accepted solution.

Hello @kiran121 ,
The problem is that Oxygen is using Cloudflare Worker under the hood, and it is not a Node.js environment; it already has a built-in "crypto" module, and the remix-validated-form importing this package will cause the error.
In this case, you can try setting "serverNodeBuiltinsPolyfill" in the remix config like follows:

serverNodeBuiltinsPolyfill: {
modules: {
crypto: true, // Provide a JSPM polyfill
},
},


Reference: https://remix.run/docs/en/main/file-conventions/remix-config#servernodebuiltinspolyfill

Helping merchants build super unique, high-performance storefronts using Weaverse + Hydrogen.
Looking for Development & Agency partners.
If you find the answer helpful, give it a thumbs up!
Our App: Theme Customizer for Shopify Hydrogen
Join our Weaverse + Hydrogen community: Weaverse Community
kiran121
Shopify Partner
5 0 3

Thank you so much, now it's working perfectly.