canvas-sketch icon indicating copy to clipboard operation
canvas-sketch copied to clipboard

Cannot import: GLTFLoader

Open el-schneider opened this issue 5 years ago • 5 comments

Hi Matt,

I'm getting this error when trying to import the GLTFLoader in a project. I guess it has something to do with browserify, but after fiddling around with it for hours I couldn’t get it running. Any hint on what might be missing? Your help would be greatly appreaciated.

'import' and 'export' may appear only with 'sourceType: module' line 1, column 0 cs-test/node_modules/three/examples/jsm/loaders/GLTFLoader.js

el-schneider avatar Oct 13 '20 09:10 el-schneider

I think canvas-sketch has a few issues importing ES modules from node_modules. Best thing to do for now is import the three/examples/js (legacy) folder like the canvas sketch ThreeJS template does for the orbit controls utility.

https://github.com/mattdesl/canvas-sketch-cli/blob/master/src/templates/three.js#L5

Once I’m done my current project I’ll probably take a closer look at canvas-sketch bundling, and use esbuild or similar to allow for ES module support and other new JS features.

On Oct 13, 2020, at 10:59 AM, el-schneider [email protected] wrote:

 Hi Matt,

I'm getting this error when trying to import the GLTFLoader in a project. I guess it has something to do with browserify, but after fiddling around with it for hours I couldn’t get it running. Any hint on what might be missing? Your help would be greatly appreaciated.

'import' and 'export' may appear only with 'sourceType: module' line 1, column 0 cs-test/node_modules/three/examples/jsm/loaders/GLTFLoader.js

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

mattdesl avatar Oct 13 '20 10:10 mattdesl

Cool. Thanks.

el-schneider avatar Oct 13 '20 15:10 el-schneider

Just want to add, that this is also an issue for the helpers, like three/examples/jsm/helpers/VertexNormalsHelper.js, and the helpers are only available in the jsm directory ... as far as i can tell.

Thanks for a very nice tool :)

CarstenHoyer avatar Jan 18 '21 13:01 CarstenHoyer

@mattdesl This could be usefull https://github.com/pmndrs/three-stdlib

CarstenHoyer avatar Feb 28 '21 11:02 CarstenHoyer

I am running into this module issue with increasing frequency, most recently with d3/d3-interpolate and mapbox/delaunator. Is there a standard workaround? For some I have been able to just install an older version, but it doesn't always work.

awaer avatar Dec 03 '21 22:12 awaer