gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.39k stars 247 forks source link

Unable to resolve module `three-mesh-bvh` (Native / Expo) #366

Closed neilgamb closed 2 years ago

neilgamb commented 2 years ago

Problem description:

I just installed three, r3f and drei in an expo app via the instructions here.

The app is running on both native and web via expo's react-native-web interface. So far everything is working OK on web.

When importing import { useGLTF, Center } from '@react-three/drei/native' however, I am getting the following error message on the native device (iPad):


While trying to resolve module `three-mesh-bvh` from file `/Users/neilsongamble/Dev/Scandy/project-chewie/apps/frontend/node_modules/@react-three/drei/native/index.js`, the package `/Users/neilsongamble/Dev/Scandy/project-chewie/apps/frontend/node_modules/three-mesh-bvh/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/neilsongamble/Dev/Scandy/project-chewie/apps/frontend/node_modules/three-mesh-bvh/build/index.umd.cjs`. Indeed, none of these files exist:

  * /Users/neilsongamble/Dev/Scandy/project-chewie/apps/frontend/node_modules/three-mesh-bvh/build/index.umd.cjs(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  * /Users/neilsongamble/Dev/Scandy/project-chewie/apps/frontend/node_modules/three-mesh-bvh/build/index.umd.cjs/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)

IMG_66E12EFDEC16-1

Suggested solution:

none so far sorry

gkjohnson commented 2 years ago

I am not an expert in expo, unfortunately, but from the error it sounds like this is an issue with expo. Have you tried making an issue there?

... /three-mesh-bvh/build/index.umd.cjs(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)

Specifically it seems that expo is not even trying to load index.umd.cjs (which exists if you look in the directory) and instead trying a variety of other extensions on the provided file instead, which is odd. The cjs extension is one of the recommended ways from node.js for distinguishing and supporting commonjs "require"-style files compared to modules (mjs) files.

neilgamb commented 2 years ago

Great. Thank for you the clarification. I actually started by first reaching out to the drei maintainers and they directed me to you ha. No worries I will follow up with them.

gkjohnson commented 2 years ago

No problem -- I'm gonna close this for now but in the interest of keeping these issues connected it looks like this is your issue for Drei. If you can post the one you make for expo here, as well, that would be great! And feel free to ping me in the relevant issue if there are other questions / discussions I can be useful for!

If it looks like something does need to be fixed here we can reopen or create a new issue.