0

https://github.com/unegma/react-three-fpscontrols

I have forked a repo which isn't working for me, and am trying to get it to work as an installable module: npm install @unegma/react-three-fpscontrols

When I try to use it, I keep getting the error:

FPSControls.js:42 Uncaught TypeError: THREE.Vector3 is not a constructor
    at ./node_modules/@unegma/react-three-fpscontrols/dist/FPSControls.js

Looking into this further, the 'THREE' object is:

{0: '/', 1: 's', 2: 't', 3: 'a', 4: 't', 5: 'i', 6: 'c', 7: '/', 8: 'm', 9: 'e', 10: 'd', 11: 'i', 12: 'a', 13: '/', 14: 't', 15: 'h', 16: 'r', 17: 'e', 18: 'e', 19: '.', 20: '0', 21: '3', 22: '7', 23: '0', 24: '0', 25: '7', 26: '3', 27: '6', 28: '3', 29: '8', 30: 'f', 31: '1', 32: '4', 33: '1', 34: '4', 35: '4', 36: 'b', 37: '3', 38: '1', 39: '8', 40: '.', 41: 'c', 42: 'j', 43: 's', default: '/static/media/three.0370073638f14144b318.cjs'}

Which leads me to think it might be an issue with threejs not supporting import (hence the cjs extension).

This answer seems to suggest that the wrong file is being included: Three.js - TypeError: THREE.Scene is not a constructor

And I looked at this answer too which might be a solution as well: How to make npm package that uses three.js with no dependece?

Either way, the original repo which I forked: https://github.com/herval/react-three-fpscontrols, uses 'rollup'.

Is this issue here, that threejs just doesn't support import syntax, or have I configured my package tsconfig file incorrectly? Or maybe I have just imported three incorrectly, or set up my peer dependencies wrongly?

Or maybe this issue I'm having, exactly the same as this one?: unable to import THREE.js in es6

timhc22
  • 7,213
  • 8
  • 48
  • 66

0 Answers0