我按照官方页面上的说明安装了 bootstrap、popper.js 和 jquery。使用 npm 包管理器。但是通过在 app.js 中要求它们,它会向我发送此错误。
这是 app.js
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const helmet = require('helmet');
require('@popperjs/core');
require('jquery');
require('bootstrap');
//Initializations.
const app = express();
//Importing routes.
const indexRoutes = require('./routes/index.router');
//Settings
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
//Midlewares
app.use(helmet());
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: false }));
//Routes
app.use('/', indexRoutes);
//Static Files
app.use(express.static(path.join(__dirname, 'public')));
//Start Server
app.listen(app.get('port'), () => {
console.log('Server on port: ', app.get('port'));
});
这是错误。 我安装了 bootstrap、jquery 和 popper。
npm install bootstrap@next
npm 我@popperjs/核心
npm 安装 jquery
C:\Users\erve\Desktop\NodeJS\Facebook\node_modules\bootstrap\dist\js\bootstrap.js:257
var isRTL = document.documentElement.dir === 'rtl';
^
ReferenceError: document is not defined
at C:\Users\erve\Desktop\NodeJS\Facebook\node_modules\bootstrap\dist\js\bootstrap.js:257:15
at C:\Users\erve\Desktop\NodeJS\Facebook\node_modules\bootstrap\dist\js\bootstrap.js:7:83
at Object.<anonymous> (C:\Users\erve\Desktop\NodeJS\Facebook\node_modules\bootstrap\dist\js\bootstrap.js:10:2)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\erve\Desktop\NodeJS\Facebook\app.js:8:1)
[nodemon] app crashed - waiting for file changes before starting...