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

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.

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

3 Likes

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

2 Likes