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

Hi! What if I can’t use CDN
I’m working with webjars before migrating 127 → 128 everything worked fine.

same as with any other package in the javascript eco system, if you cant use cdns you need a bundler. it did somewhat work before due to a bug or workaround. that’s fixed and now browser imports work as you’d expect: they don’t, because the spec is incomplete and cannot handle dependencies. there’s a benefit for the small cost of adding a build tool, your distribution will be smaller, faster and safer (support old browsers).