Import error in app.js

This is the error:
Uncaught TypeError: Failed to resolve module specifier “three”. Relative references must start with either “/”, “./”, or “…/”.

here is the github repo:

using npm, node_modules to access Three.js

You need Webpack or tsc

1 Like

You are using a bare import specifier which is currently not supported in browsers. It will work as soon as Import maps are available.

If you don’t want to use a build tool like Webpack or rollup, you can also import modules over a CDN e.g.:

import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.118.3/build/three.module.js';
1 Like

okay thanks, how come we can use type"module" then? what does that mean?

Check out: https://jakearchibald.com/2017/es-modules-in-browsers/

1 Like

Okay thanks. What is bare import vs say regular or es modules?

This is also explained in the article. I suggest you study ES6 modules a bit since there are many existing resources about this topic.

1 Like