admin管理员组文章数量:1336729
I need to render some text in my threejs project, but every time I add the module
import { FontLoader } from '.js';
import { TextGeometry } from '.js';
this error is thrown
Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”. FontLoader.js:5:7
Which is ing from FontLoader.js. If I don't include any of it three js render the scene and works fine. In my network log, it runs flawless and all modules are 200 OK.
I need to render some text in my threejs project, but every time I add the module
import { FontLoader } from 'https://threejs/examples/jsm/loaders/FontLoader.js';
import { TextGeometry } from 'https://threejs/examples/jsm/geometries/TextGeometry.js';
this error is thrown
Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”. FontLoader.js:5:7
Which is ing from FontLoader.js. If I don't include any of it three js render the scene and works fine. In my network log, it runs flawless and all modules are 200 OK.
Share Improve this question asked Mar 21, 2022 at 12:15 Luke DelrayLuke Delray 651 silver badge10 bronze badges2 Answers
Reset to default 5You have to use an import map with latest three.js
releases. Besides, never import modules directly from https://threejs
. Always use a CDN like below:
<script async src="https://unpkg./[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg./[email protected]/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { FontLoader } from 'https://unpkg./[email protected]/examples/jsm/loaders/FontLoader.js';
import { TextGeometry } from 'https://unpkg./[email protected]/examples/jsm/geometries/TextGeometry.js';
The polyfill es-module-shims.js
is currently required in Firefox and Safari.
The error you are receiving is because you are importing JS example files whose are in fact ESM modules, but inside them they have imports from three
that cannot be resolved.
ThreeJS exports FontLoader
and TextGeometry
so you just need to import a EcmaScript Module (ESM) from a CDN to import, for example:
import { FontLoader, TextGeometry } from 'https://cdnjs.cloudflare./ajax/libs/three.js/r128/three.module.js';
By that way they will be available in Chrome.
本文标签: javascriptfontloader and textgeometry not working in threejsStack Overflow
版权声明:本文标题:javascript - fontloader and textgeometry not working in threejs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742304976a2449733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论