Three.js: JSM / GLTFLoader: Webpack error using jsm

Created on 9 Mar 2019  路  3Comments  路  Source: mrdoob/three.js

Description of the problem

I麓m using three.js in an Angular project with webpack as bundler.
When trying to load a GLTF file a ReferenceError is thrown:

ERROR Error: Uncaught (in promise): ReferenceError: THREE is not defined ReferenceError: THREE is not defined at GLTFLoader.js:2715

Referring to this line of code:

https://github.com/mrdoob/three.js/blob/1bb6d19805a30e6edb5650d40ab248a3f9ce918e/examples/jsm/loaders/GLTFLoader.js#L2715

In my TypeScript code, I import the loader this way:

import { GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader';

I guess to fix this, either _BufferGeometryUtils_ hast to be exported in _three.module.js_ or the code block has to be removed from the jsm version of GLTFLoader, as the global _THREE_ object is not defined.

I also found that _BufferGeometryUtils_ is an exception in the _modularize_ script:

https://github.com/mrdoob/three.js/blob/e88edaa2caea2b61c7ccfc00d1a4f8870399642a/utils/modularize.js#L15

Three.js version
  • [ ] Dev
  • [x ] r102
  • [ ] ...
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)
Bug

Most helpful comment

I麓ve tryed the updated GLTFLoader in dev branch and it麓s working fine, waiting for the release.
Thanks for the fix!

For anyone that needs an urgent fix, use the 'three-gltf-loader' npm package:

import GLTFLoader from 'three-gltf-loader';

All 3 comments

Unfortunately the examples/jsm modules aren't fully functional yet sorry. Still working on this.

An other user reported the same problem here:

https://discourse.threejs.org/t/importing-three-r102-examples-jsm-gltfloader-into-angular-7-project/6484

Merging #15582 should solve this issue, right?

I麓ve tryed the updated GLTFLoader in dev branch and it麓s working fine, waiting for the release.
Thanks for the fix!

For anyone that needs an urgent fix, use the 'three-gltf-loader' npm package:

import GLTFLoader from 'three-gltf-loader';

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donmccurdy picture donmccurdy  路  3Comments

zsitro picture zsitro  路  3Comments

konijn picture konijn  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments

Horray picture Horray  路  3Comments