Even when trying to load with ObjLoader, it throws an error
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { createCanvas } = require('node-canvas-webgl')
const THREE = require('three')
const width = 1000, height = 1000
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
const loader = new THREE.ObjectLoader();
loader.load(
// resource URL
"/Users/david/Downloads/Chemex_Mug.obj",
// onLoad callback
// Here the loaded data is assumed to be an object
function ( obj ) {
// Add the loaded object to the scene
scene.add( obj );
},
// onProgress callback
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// onError callback
function ( err ) {
console.error( 'An error happened' );
}
);
const canvas = createCanvas(width, height)
const renderer = new THREE.WebGLRenderer({
canvas
})
/Users/david/Documents/Work/3drender/node_modules/three/build/three.cjs:28598
const req = new Request(url, {
^
ReferenceError: Request is not defined
at FileLoader.load (/Users/david/Documents/Work/3drender/node_modules/three/build/three.cjs:28598:15)
Importing three/examples/jsm/loaders/GLTFLoader.js has been the recommended import path in past releases. Importing three/examples/jsm/loaders/GLTFLoader (no .js extension) has never been recommended; some ESM tools support it but many do not.
Support for Node.js environments in three.js has always been “best effort”, you’ll certainly find problems that require workarounds if you’re trying to load models and render screenshots in Node.js. three.js relies on many Web APIs, including WebGL, image loading, Blobs, Web Workers, etc. The (external) three-stdlib project includes many of the workarounds you’d need to use Node.js, and may be helpful.
that sounds like a classic path problem. all modules refer directly to “three” folder as if you didn’t have any subfolders. Please open your GLTF loader and look for the path. then change this to “from …/…/…/build/three.module.js’;”
on default it is “from ‘three’;”
the section of code should then look something like this, depending on which version you have.