0
\$\begingroup\$

I'm looking at this three.js cubemap example, and it runs fine in my browser when loaded from that page.

After much strain to find and download the files - it does not run?

What am I doing wrong, with this "module" stuff?

I got it to work by changing:


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

Into:

<script src="three.js"></script>
<script>
...

Can anyone explain how to properly import three.module.js? Why is this change necessary when I run the project on my machine?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

you should try changing this line:

import * as THREE from 'three.module.js';

to this line:

import * as THREE from './three.module.js';

so the browser understand that it is a Relative Import and it works.

\$\endgroup\$
4
  • \$\begingroup\$ Thank you for your reply, Ashkan. Although, with latest Chrome (can't turn off updates), that change didn't work. Also Chrome ctrl-s rewrites the save with new subdir - which is why you cannot save the original, nor did it write the three.module.js. Seems user unfriendly. \$\endgroup\$ Commented Oct 17, 2020 at 22:27
  • \$\begingroup\$ Thanks also go to DMGregory for informing map TYPE : equirectangular : could likely learn how now. \$\endgroup\$ Commented Oct 17, 2020 at 22:38
  • \$\begingroup\$ import * as THREE from './three.module.js'; Failed to load resource: net::ERR_FILE_NOT_FOUND -- file placed in same dir and parent dir. parent dir would be ../ \$\endgroup\$ Commented Oct 17, 2020 at 23:12
  • \$\begingroup\$ edit the working file this time.. not the saved file -- Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec. \$\endgroup\$ Commented Oct 17, 2020 at 23:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.