pmndrs / ecctrl

🕹ī¸ A floating rigibody character controller
MIT License
467 stars 50 forks source link

Error when app in production #6

Closed Romaixn closed 9 months ago

Romaixn commented 9 months ago

Hello! Personally, I'm encountering an error when deploying an application using this package. Has anyone else tried deploying it, or could the error be on my end? (I'm using Vercel personally)

Here's the specific error: TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))

I'm using Vite and React latest versions

ErdongChen-Andrew commented 9 months ago

I'm using Vercel for my live demo and there is no error: https://character-control.vercel.app/ It would be really helpful if you could provide more detailed error messages.

Magvin commented 9 months ago

@Romaixn can you eleborate what line of code it throws it? What framework you use? React | Nextjs?

Romaixn commented 9 months ago

Oh, I see. It must be something on my end if it works for you on Vercel! I'm using React with Vite. Here's the URL to the Vercel deployment: https://zombie-runner.vercel.app (App error when loading 3D scene after welcome screen)

If I comment the <Ecctrl> Component my app work well in Vercel, of course, I don't have any issues during development... That's why it's really complicated to debug.

Magvin commented 9 months ago

I do assume it complains about keyboard controls. Might be wrong you need to find out what he is trying to make with that useContext

image image
Romaixn commented 9 months ago

Indeed, that could be it... yet I have exactly the same configuration as in the demo: https://codesandbox.io/s/ecctrl-w-o-animations-3k3zxt?file=/src/App.js. And when I remove just <Ecctrl> and leave <KeyboardControls>, everything works correctly.

I'll investigate a bit to see where the issue might be coming from

ErdongChen-Andrew commented 9 months ago

@Romaixn I recently encountered a similar issue on CodeSandbox. I managed to resolve it by updating ecctrl, drei, and fiber to the latest versions. Give it a try, let me know if it works for you 😁

drcmda commented 9 months ago

@Romaixn I recently encountered a similar issue on CodeSandbox. I managed to resolve it by updating ecctrl, drei, and fiber to the latest versions. Give it a try, let me know if it works for you 😁

@ErdongChen-Andrew i think it's this: https://github.com/pmndrs/ecctrl/blob/main/package.json#L32C1-L42C4

these should be peer dependencies. otherwise it's going to cause multiple three's, fiber's, drei's to be loaded. the issue is that ecctrl's context of fiber doesn't match the one of the main app, this happened due to version mismatch. the bundler just makes sure that ecctrl gets the exact fiber (and every other lib) that's declared in package.json.

imo it should be like this:

  "devDependencies": {
    "@types/react-dom": "^18.2.8",
    "@vitejs/plugin-react": "^4.1.0",
    "typescript": "^5.2.2",
    "vite": "^4.3.9"
  },
  "peerDependencies": {
    "@react-three/drei": ">=9.0",
    "@react-three/fiber": ">=8.0",
    "@react-three/rapier": ">=1.0",
    "react": ">=18.0",
    "react-dom": ">=18.0",
    "three": ">=0.133",
    "zustand": ">=4.0"
  },
  "dependencies": {
    "leva": "^0.9.34",
    "r3f-perf": "^7.1.2"
  }

i don't know about leva and r3f-perf. are these used for the debug view? in that case they could be "dependencies". if it's for local examples only they have to be "devDependencies"

btw erdong, would you like to be in pmndrs discord? https://discord.gg/poimandres a couple of people have asked for cctrl to have its own channel. this would make it easier to gather input or contributions/contributors. or figure out new api surfaces in small teams etc.

dswhy commented 9 months ago

I had the same problem and solved it by changing the dependencies above 👍 :)

Thanks @drcmda

ErdongChen-Andrew commented 9 months ago

👍 Thanks @drcmda! @CodyJasonBennett helped fix the npm config, and everything works perfectly now! It would be great if ecctrl could have its own channel. I already in the discord, I just barely check messages there 😅.