mattdesl / canvas-sketch

[beta] A framework for making generative artwork in JavaScript and the browser.
MIT License
5.01k stars 393 forks source link

Cannot import: GLTFLoader #109

Open el-schneider opened 3 years ago

el-schneider commented 3 years ago

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

mattdesl commented 3 years ago

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 notifications@github.com 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.

el-schneider commented 3 years ago

Cool. Thanks.

CarstenHoyer commented 3 years ago

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 commented 3 years ago

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

awaer commented 2 years ago

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.