MODULE vs. regular SCRIPT problems

I have an HTML page that has some “regular” in-line javascript, meaning code created using the good-old <script> tag.

-I also have a <script type="module"> section a bit further down so I can do this:

import { OrbitControls } from "./node_modules/three/examples/jsm/controls/OrbitControls.js";

Problem is when I try call a function that’s in the <script type="module"> from the regular <script> section I keep getting errors.

I tried putting all the code in <script type="module"> section, but I’m still getting errors.

I know I’m not sharing any specific code here, but are there just some sort of generic do’s and don’t’s that I need to be aware of to get this working? What’s going on here - isn’t it all just javascript, and shouldn’t the HTML page “see” all of it once the page is loaded?

Nop, kinda the point of using modules in the first place.

If you want to stick with the old-school JS, a quick and simple fix would be to just use:

<script src="//cdn.jsdelivr.net/gh/mrdoob/three.js@r153/examples/js/controls/OrbitControls.js"></script>

Instead of import { OrbitControls } from "./node_modules/three/examples/jsm/controls/OrbitControls.js"; (and removing the type="module" ofc.) Then you can access OrbitControls as THREE.OrbitControls.

If you prefer the modules, just don’t use global / unscoped JS (you can still make things global by assigning them as properties of the window object, but it’s probably best to avoid it.)

I tried the CDN URL you provided but it’s not working.

I added https:// but that doesn’t work either.

Are you sure you gave me the right URL?