【发布时间】:2021-06-28 05:30:18
【问题描述】:
我正在尝试使用 scrollreveal javascript。通过 npm 安装它并在我的 NodeJS 代码中使用它(见下文)。另外,我也将它包含在我的 HTML 中。
现在,当我在超级终端中运行 nodemon app.js 时,我得到了这个错误:
C:\Users\Admin\Desktop\My Projects\test\node_modules\scrollreveal\dist\scrollreveal.js:33 容器:document.documentElement, ^
ReferenceError: 文档未定义
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>
<h1>Hello</h1>
<script src="https://unpkg.com/scrollreveal@4.0.9/dist/scrollreveal.min.js"></script>
</body>
</html>
app.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const ScrollReveal = require('scrollreveal');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(3000, function () {
console.log('server start on port 3000');
});
【问题讨论】:
-
为什么要将它包含在 app.js 中?这似乎是一个只适用于“浏览器”的包,不适用于 NodeJS。
-
我不知道。我对此真的很陌生:(谢谢
标签: javascript node.js scrollreveal.js