Uncaught ReferenceError: OBJLoader2 is not defined

I’m getting this error in the browser console. I was trying to simply load a .obj model from /examples directory. Basically i have 2 files: .html file with all the import needed and a .js file for the script. I imported <script type="module" src="loader/OBJLoader2.js"></script> and i have this code snippet:

const objloader = new OBJLoader2();
  objloader.load( 'models/obj/Cerberus.obj', ( root ) => {
    scene.add(root);
  });

What am i doing wrong?

Try to import OBJ2Loader like so:

import { OBJ2Loader } from './loaders/OBJLoader2.js';

So similar to the official exmaple.

If i put this type of import in my script file, i get this error “Uncaught SyntaxError: Cannot use import statement outside a module”

It seems you have to add type="module" to your script tag that contains your application code.

But the problem is that i have 2 different file:

  1. .html with the following code:
demoThreeJs body { margin: 0; } canvas { display: block; }
  1. .js file named “script.js” with the code that performs all the operations

And now i get this error: "Uncaught SyntaxError: The requested module ‘./loader/OBJLoader2.js’ does not provide an export named ‘OBJ2Loader’ " but referred to the .html file

Ok, i rewrited my code, in order to avoid the previous import methods, putting the script between the tag, and using only ‘import {} from’ syntax. Now i’ve re-downloaded OBJLoader2.js. In the first lines of code it says:

import {
FileLoader,
Object3D,
Loader
} from “…/…/…/build/three.module.js”;

import { OBJLoader2Parser } from “./obj2/OBJLoader2Parser.js”;
import { MeshReceiver } from “./obj2/shared/MeshReceiver.js”;
import { MaterialHandler } from “./obj2/shared/MaterialHandler.js”;

Do i have to dowload this files too and change the path in OBJLoader2.js file?