0

I'm trying to get a 3js demo to work on codesandbox, or codepen or jsfiddle (any is fine). I think the issue is perhaps that the script is module based, but I'm not sure what to google.

This is the demo I want to copy onto one of these platforms https://threejs.org/examples/?q=instan#webgl_instancing_performance

My attempt (replaced relative path modules with CDNs) https://codesandbox.io/s/gltf-instances-yly6m?file=/src/index.js

thanks!

StephD
  • 266
  • 3
  • 20

1 Answers1

0

Using javascript modules requires the script to have type="module"

<script src="src/index.js" type="module"></script>

More information here under "Applying the module to your HTML" section: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html

Codesandbox lets you add npm dependencies on the left under "Dependencies" and use them in the javascript file. Attached a screenshot: Codesandbox npm package import

Codepen also lets you add npm packages in the "Pen settings" section: Codepen npm package import

Deep
  • 532
  • 3
  • 10