英文:
How to use node-modules installed by npm from template
问题
我正在尝试在Go模板中使用通过npm安装的库。
我通过'npm install three'安装了必要的三个库,保存在根文件夹中,如下面的截图所示。
之后,我尝试导入和使用three.js模块,但是找不到threejs。
我认为文件系统存在一些问题,我该如何在我的情况下无问题地使用threejs?
import * as THREE from "/three";
class App{
constructor(){
// 场景
const scene = new THREE.Scene();
// 相机
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
// 渲染器
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.render(scene, camera);
}
}
window.onload = function(){
new App();
}
错误信息
import * as THREE from "/three";
http://localhost:8081/three net::ERR_ABORTED 404 (Not Found)
import * as THREE from "three";
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
在main.go中使用e.Static("/node", "node_modules")
import * as THREE from "/node/node_modules/three/builld/three.module.js";
GET http://localhost:8081/node/three/builld/three.module.js net::ERR_ABORTED 404 (Not Found)
英文:
I am trying to use a library installed by npm in the Go template.
I installed the necessary three libraries through 'npm install three', saved in the root folder as shown in the screenshot below.
After that, I try to import and use the three.js module as shown below, but threejs is not found.
I think there is some problem with the filesystem, how can I use threejs without problems in my situation?
import * as THREE from "/three";
class App{
constructor(){
// 장면
const scene = new THREE.Scene();
// 카메라
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
// 렌더러
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.render(scene, camera);
}
}
window.onload = function(){
new App();
}
error
import * as THREE from "/three";
http://localhost:8081/three net::ERR_ABORTED 404 (Not Found)
import * as THREE from "three";
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
e.Static("/node", "node_modules") in main.go
import * as THREE from "/node/node_modules/three/builld/three.module.js";
GET http://localhost:8081/node/three/builld/three.module.js net::ERR_ABORTED 404 (Not Found)
答案1
得分: 1
以下是翻译好的内容:
<script type="importmap">
{
"imports": {
"three": "/node/three/build/three.module.js"
}
}
</script>
通过修正作业的路径,问题已解决。
英文:
<script type="importmap">
{
"imports": {
"three": "/node/three/build/three.module.js"
}
}
</script>
It was resolved by correcting the path to the job.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论