javascript - Javascript 给我 Uncaught ReferenceError: require is not defined 错误
问题描述
我的 index.js 有这个代码
const THREE = require("three")
var scene = new THREE.scene();
console.log(scene)
我的 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="webgl-output">What the hell</div>
<script src="./index.js"></script>
</body>
</html>
我没有在 package.json 中使用标签 { type : "modules }。但是,我仍然收到 Uncaught ReferenceError: require is not defined 错误。我可以知道是什么原因吗?谢谢!
如果您有兴趣,这是我的 package.json
{
"name": "threejs-playground",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"three": "^0.133.1"
}
}
解决方案
推荐阅读
- javascript - 登录和重定向用户脚本失败,没有错误,也没有重定向?
- c++ - Qt5 堆叠小部件
- ios - 如何使用 for 循环实时向 UIScrollView 添加许多 UIButton?
- javascript - 你怎么能 console.log 只有前 100 行?
- r - 如何告诉ggplot选择用``引用的列
- mysql - SQL 错误 1064 声明 @VAR
- java - 将形状拖放到 JavaFX 中的另一个窗格
- go - 我的静态文件没有正确呈现
- python - Python 类条件:从 x 输入获取 [x,x] 输出?
- batch-file - 批量复制并在新位置重新打开