Three.js ์์ Uncaught TypeError: Failed to resolve module specifier "three"... ์๋ฌ ํด๊ฒฐ๋ฒ
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../"
์ถ์ฒ
: https://stackoverflow.com/questions/68160473/failed-to-resolve-module-specifier-thre
Three.js์ RectAreaLightUniformsLib๊ณผ ๊ฐ์ ES6 ๋ชจ๋์ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ์์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ ๋๊ฐ ์๋ค.
Three.js๋ฅผ npm ๋ชจ๋๋ก ์ค์นํ์ง ์๊ณ ๊ณต์ ์ฌ์ดํธ์์ ๋ฐฐํฌํ๋ ํ์ผ์ ๋ค์ด๋ก๋ํด์ ์ฌ์ฉํ๊ณ ์๋ค๋ฉด ์๋์ ๊ฐ์ด ์์ ํด์ค๋ค.
1. index.html ํ์ผ์ importmap์ ์ถ๊ฐ (๊ฒฝ๋ก๋ฅผ ์ ํ์ธํ๊ธฐ)
<!-- index.html -->
<script type="importmap">
{
"imports": {
"three": "../three/build/three.module.js",
"three/examples/jsm/controls/OrbitControls":"../three/examples/jsm/controls/OrbitControls.js",
}
}
</script>
<script type="module" src="main.js" defer></script>
2. ์คํฌ๋ฆฝํธ์ import ๋ฌธ์ to-be ์ ๊ฐ์ด ์์
// main.js
// as-is
import * as THREE from '../three/build/three.module.js'
import { OrbitControls } from '../three/examples/jsm/controls/OrbitControls.js';
// to-be
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
โป importmap ์ ์ง์ ๋ฒ์ : https://caniuse.com/import-maps