Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: "module is not defined" in Hydrogen/Remix Apps with new Vite when using @react-three/drei #2175

Closed
nhm1990 opened this issue May 30, 2024 · 2 comments

Comments

@nhm1990
Copy link

nhm1990 commented May 30, 2024

What is the location of your example repository?

https://github.com/nhm1990/hydrogen-quickstart

Which package or tool is having this issue?

hydrogen-react

What version of that package or tool are you using?

2024.4.2

What version of Remix are you using?

2.8.0

Steps to Reproduce

  1. Run sample repo "hydrogen-quickstart"
  2. npm install
  3. npm run dev
  4. Open http://localhost:3000/
  5. See error: ReferenceError: module is not defined

Expected Behavior

Sample .glb file is loaded in the canvas without errors and app works.

Actual Behavior

Error: "ReferenceError: module is not defined" appears

Could only reproduce it with hydrogen apps/remix since using Vite.
With pure remix, react or nextJS app it's working fine.

ReferenceError: module is not defined
at C:/Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@react-three/fiber/node_modules/react-reconciler/constants.js:6:3
at Object.runViteModule (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1181:17)
at ViteRuntime.directRequest (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1026:78)
at ViteRuntime.cachedRequest (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:949:28)
at request (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:976:128)
at /node_modules/@react-three/fiber/dist/index-ba8afaa4.esm.js?v=3cd111ea:3:31
at Object.runViteModule (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1181:11)
at ViteRuntime.directRequest (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:1026:60)
at ViteRuntime.cachedRequest (Users/max.mustermann/Projects/Example Shopify/hydrogen-quickstart-1/node_modules/@shopify/mini-oxygen/dist/vite/worker-entry.js:950:79)
at /node_modules/@react-three/fiber/dist/react-three-fiber.esm.js?v=3cd111ea:1:110

Also with older versions it's not working.

Maybe related: facebook/react#20327

@frandiox
Copy link
Contributor

Hi 👋
Please try what's explained here: #2129 (comment)

Let me know if that doesn't work.

@nhm1990
Copy link
Author

nhm1990 commented May 31, 2024

Hey @frandiox , this did the trick. I had to add some more stuff to the array until it worked.
Thanks a lot!

export default defineConfig({
...
ssr: {
    optimizeDeps: {
      include: [
        '@react-three/fiber',
        '@react-three/drei',
        'react',
        'react-dom',
        'react-dom/client',
        'prop-types',
        'react-dropzone',
        'merge-value',
      ],
    },
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants