-2

In the browser console throws this error , --Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".-- I am just a beginner in threejs. Please help!! I tried finding the Webgl2.0 compute flag but it is not available, but when i check about:config , it shows Webgl webgl 2.0 both as hardware accelerated

Was expecting a black screen and a geometry figure exactly shown in tutorial.

  • Does this answer your question? [Import from node\_modules not recognized in es6 modules in browser](https://stackoverflow.com/questions/52558777/import-from-node-modules-not-recognized-in-es6-modules-in-browser) – Konrad Jun 04 '23 at 20:06

1 Answers1

0

See the instructions for using Three.js.

You appear to be following "Option 1: Install with NPM and a build tool" but you have skipped the part about using a build tool and are trying to run the code directly in a browser.

When using <script type="module"> directly in a browser, imports must be from URLs (and relative URLs must start with /, ./ or ../ as the error message says) and not just module names. (Note that just using a URL to three.js is unlikely to work as it probably imports other modules).

Node.js supports import from just module names. Browsers are not Node.js.

Build tools (like Vite which is used in the Three.js documentation) support using just module names. You failed to use a build tool.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335