Shopify / hydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.
https://hydrogen.shop
MIT License
1.19k stars 241 forks source link

External modules are not supported #2029

Closed lukszy closed 3 weeks ago

lukszy commented 4 weeks ago

What is the location of your example repository?

No response

Which package or tool is having this issue?

Oxygen

What version of that package or tool are you using?

3.0.0

What version of Remix are you using?

2.8.0

Steps to Reproduce

  1. Create the app using latest npm create @shopify/hydrogen@latest -- --quickstart
  2. Add import crypto from 'node:crypto'; in _index.jsx
  3. In that same file in the loader method add const hash = crypto.createHmac('sha256', 'secret');
  4. Run the application npm run dev

Node v20.12.2 npm 10.5.0 OS MacOS Sonoma 14.4.1

Expected Behavior

Should be able to use node packages like crypto package

Actual Behavior

Error: [o2:runtime] External modules are not supported: "node:crypto"
    at Object.runExternalModule (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1153:17)
    at ViteRuntime.directRequest (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:981:42)
    at ViteRuntime.cachedRequest (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:949:28)
    at request (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:976:128)
    at /app/routes/_index.jsx:6:31
    at Object.runViteModule (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1171:11)
    at ViteRuntime.directRequest (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1026:60)
    at ViteRuntime.cachedRequest (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:950:79)
    at /@id/__x00__virtual:remix/server-build:28:32
    at Object.runViteModule (Users/user/test-app/hydrogen-quickstart/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1171:11)
blittle commented 3 weeks ago

By default, Hydrogen is setup to run on Oxygen. Oxygen uses a worker runtime, not NodeJS. This means you cannot use NodeJS APIs. If you'd like to deploy to Node, please follow the express example, which does not use our CLI.