1

I'm playing a little with three.js for a WebGL based visualization. I found quite good examples on https://threejsfundamentals.org/ but I run into problems when I'm trying to run these locally on my PC.

I have copied the complete HTML example with embedded JavScript code, it includes three.module.js using the absolute URL:

<script type="module">
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/build/three.module.js';
...

The result is, that it draws me the example visualization. If I change this to the local path of the module it fails to load (the module is present locally at this URL (relative to the index.html I'm writing).

<script type="module">
import * as THREE from 'resources/threejs/build/three.module.js';
...

Thanks for pointing out the error, I think it's a misunderstanding about loading modules in Javascript.

gman
  • 100,619
  • 31
  • 269
  • 393
Cookie
  • 678
  • 1
  • 11
  • 22
  • 2
    You need to set up a server to load local files stored in your hard-drive. You can read about [setting a local server in the docs](https://threejs.org/docs/#manual/en/introduction/How-to-run-things-locally). This question has been asked here: ["Cross origin requests are only supported for HTTP." error when loading a local file](https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local) – M - Nov 24 '20 at 22:13
  • 1
    This is covered in [this article](https://threejsfundamentals.org/threejs/lessons/threejs-setup.html) – gman Nov 25 '20 at 06:21
  • Im using xamp and three.module.js is located in ./js/ folder but Im getting an error Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../". And I cant figure it out why? – NccWarp9 Jul 27 '21 at 20:06

0 Answers0