Skip to content

ReferenceError: module is not defined from react/compiler-runtime.js via @sanity/visual-editing in Mini-Oxygen #613

Description

@mauryapatel-boop

I am encountering a runtime crash immediately upon starting my development server. The server throws a ReferenceError: module is not defined because it is trying to execute CommonJS code inside the @shopify/mini-oxygen worker environment, which strictly expects ESM and does not have the module object defined.

The error traces back to @sanity/visual-editing importing react/compiler-runtime.js (from React 19.2.4), which is formatted as CommonJS.

Steps to Reproduce:

  1. Clone the repository / set up a fresh Hydrogen headless install.
  2. Run pnpm install (using React 19.2.4 and Node 22).
  3. Set up environment variables.
  4. Run pnpm dev to start the Mini-Oxygen development server.
  5. Attempt to load the application.

Expected Behavior:
The application should render successfully without CommonJS/ESM compatibility errors in the Mini-Oxygen worker.

Actual Behavior:
The server crashes and throws a 500 error with the following stack trace:

ReferenceError: module is not defined
    at C:/GitHub/new-ecommerc-headless/node_modules/.pnpm/react@19.2.4/node_modules/react/compiler-runtime.js:13:3
    at Object.runInlinedModule (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1418:17)
    at ModuleRunner.directRequest (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1281:82)
    at ModuleRunner.cachedRequest (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1176:28)
    at request (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1225:79)
    at C:/GitHub/new-ecommerc-headless/node_modules/.pnpm/@sanity+visual-editing@5.3._8894b6fe2021e048202f96b184033855/node_modules/@sanity/visual-editing/dist/_chunks-es/VisualEditing.js?v=69b4f217:13:182
    at Object.runInlinedModule (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1418:11)
    at ModuleRunner.directRequest (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1281:61)
    at ModuleRunner.cachedRequest (GitHub/new-ecommerc-headless/node_modules/.pnpm/@shopify+mini-oxygen@4.0.2__056f10e53a824ad3bbcdf498809f17a6/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1177:79)
    at C:/GitHub/new-ecommerc-headless/node_modules/.pnpm/@sanity+visual-editing@5.3._8894b6fe2021e048202f96b184033855/node_modules/@sanity/visual-editing/dist/react/index.js?v=69b4f217:12:31

Environment Info:

  • Node Version: v22
  • Package Manager: pnpm
  • OS: Windows
  • React: 19.2.4
  • @sanity/visual-editing: 5.3.x
  • @shopify/mini-oxygen: 4.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions