【发布时间】:2018-01-02 16:22:54
【问题描述】:
这是我的 index.js 文件:
const express = require('express')
const app = express()
app.set('views', __dirname + '/views');
app.set('view engine', 'pug')
app.get('/', function (req, res) {
res.render('index', { title: 'Hey', message: 'Hello there!' })
})
app.listen(3333, function () {
console.log('Example app listening on port 3333!')
})
index.pug 文件:
html
head
title= title
body
h1= Hello
package.json 文件:
{
"name": "@npm-private/pug_with_node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.3",
"jade": "^1.11.0",
"pug": "^2.0.0-rc.2"
}
}
当我运行我的服务器文件时,它会显示一个错误。事实上,我安装了 pug 和 jam 两个 npm 模块:
错误:找不到模块“pug” 在 Function.Module._resolveFilename (module.js:485:15) 在 Function.Module._load (module.js:437:25) 在 Module.require (module.js:513:17) 在要求(内部/module.js:11:18) 在新视图 (/home/software/node_modules/express/lib/view.js:80:30) 在 Function.render (/home/software/node_modules/express/lib/application.js:570:12) 在 ServerResponse.render (/home/software/node_modules/express/lib/response.js:971:7) 在/home/software/Harsh Patel/pug_with_node/index.js:8:7 在 Layer.handle [as handle_request] (/home/software/node_modules/express/lib/router/layer.js:95:5) 在下一个(/home/software/node_modules/express/lib/router/route.js:137:13)
【问题讨论】:
-
你用什么命令来安装这两个模块?
-
package.json 在哪里?你做了 npm install
-
确保你有
pug在 tour package.json 中 -
我的 package.json 中有哈巴狗
-
我也添加了 package.json 文件