【发布时间】:2020-04-18 14:44:49
【问题描述】:
我在观看视频并准确复制代码时不断收到此错误。
var scores, roundScore, activePlayer, dice
scores = [0,0]
roundScore = 0
activePlayer = 0
dice = console.log (Math.floor(Math.random() * (6) + 1))
console.log(dice)
document.querySelector('#current-0').textContent = dice
ReferenceError: document is not defined
at init (/Users/Nikolas/Desktop/JS/app.js:79:5)
at Object.<anonymous> (/Users/Nikolas/Desktop/JS/app.js:4:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
【问题讨论】:
-
您是否尝试在 Node.js 中打开
.js文件? -
您收到此错误是因为您在 DOM(
document、window等)所在的 服务器端节点环境中运行 JavaScript t 可用 - 这就是您收到错误的原因。 (即 NodeJS 不应运行app.js)。我不知道为什么 NodeJS 正在运行app.js- 请发布你用来启动 web 服务器和任何 bower、webpack 或 gulp 任务的命令行。
标签: javascript document