question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERR_REQUIRE_ESM when trying to use @react-three/xr with react-three-next

See original GitHub issue

I am trying to add VR functionality to a project that uses react-three-next.

Just trying to import the VRCanvas with the line:

import { VRCanvas } from '@react-three/xr'

Fails with the error: ERR_REQUIRE_ESM Must use import to load ES Module: /…/app/node_modules/three/examples/jsm/loaders/GLTFLoader.js

I tried using next-transpile-modules to load @react-three/xr but it didn’t work. And also tried using the new next.js experimental ESM feature ( { esmExternals: “loose” } ) in next.config.js without success.

Am i missing something? Is this a problem with how react-three/xr is built?

Does anyone has an idea on how to make them work?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pfortescommented, Sep 4, 2021

🌴 Success! 😄

I have managed to make it work!

it was a combination between activating the experimental esmExternals (i think this helps us with the Type: module thing) and correctly transpiling @react-three/xr and @webxr-input-profiles/motion-controllers

You can see the changes in https://github.com/pfortes/r3f-next-xr/commit/60db7ea9980f195ef3f32bee1e1991878c13ce09

And an updated sandbox at: https://codesandbox.io/s/optimistic-lamport-27d52?file=/next.config.js

Thanks for the help and motivation!

1reaction
pfortescommented, Sep 3, 2021

I have tried to transpile the example but i keep getting an error.

What i noticed is that including @react-three/xr in the next-transpile-module brakes on the build stage, giving a slightly diferent error: transpileAll3

When i dont transpile anything or i transpile ‘three’ and ‘three/examples/jsm/loaders/GLTFLoader’ i get the error: transpileThreeAndGldfLoader

i will try to make a reproduction in a codesandbox so it is easier to test

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

pmndrs/react-xr: VR/AR with react-three-fiber - GitHub
This hook gives you access to the current XRState configured by <XR /> . const { // An array of connected `XRController` controllers,...
Read more >
Why am I getting this build error with three-xr of react?
This happened to me recently where I had another package that was using a much earlier version of three and @react-three/xr decided to...
Read more >
@react-three/xr examples - CodeSandbox
Learn how to use @react-three/xr by viewing and forking @react-three/xr example apps on CodeSandbox.
Read more >
Configure 3D models with react-three-fiber - LogRocket Blog
Use react -three-fiber, a React renderer for Three.js, to build and customize 3D models on the web with a less verbose workflow.
Read more >
I wish I knew this before using React Three Fiber - YouTube
Sometimes the best way to understand a library like React Three Fiber is to compare it to the original 3D web library, Three.js....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found