WIN7下 DOWN NodeClub 启动成功后报错(Nodejs相关)
WIN7下 DOWN NodeClub 启动成功后报错(Nodejs相关)
当http://localhost:3000/访问后.报以下错误.提示 'E:\layout.html’这个是什么意思?还需哪里配置?
“D:\Program Files\JetBrains\WebStorm 8.0.2\bin\runnerw.exe” “D:\Program Files\nodejs\node.exe” app.js NodeClub listening on port 3000 in development mode God bless love… You can debug your app with http://localhost.cnodejs.org:3000 Error: ENOENT, no such file or directory 'E:\layout.html’ at Object.fs.openSync (fs.js:427:18) at fs.readFileSync (fs.js:284:15) at Object.exports.renderFile (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\ejs\lib\ejs.js:312:9) at module.exports (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\ejs-locals\index.js:85:7) at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\ejs-locals\index.js:131:7 at Object.exports.renderFile (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\ejs\lib\ejs.js:317:3) at View.module.exports [as engine] (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\ejs-locals\index.js:85:7) at View.render (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\express\lib\view.js:76:8) at Function.app.render (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\express\lib\application.js:502:10) at ServerResponse.res.render (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\express\lib\response.js:783:7) at ServerResponse.cls_wrapRender [as render] (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\newrelic\lib\instrumentation\express.js:151:21) at E:\nodejs\nodeclub-master\nodeclub-master\controllers\site.js:42:11 at [object Object]._all (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\eventproxy\lib\eventproxy.js:258:16) at [object Object].EventProxy.trigger (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\eventproxy\lib\eventproxy.js:144:22) at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\eventproxy\lib\eventproxy.js:501:21 at Promise.<anonymous> (E:\nodejs\nodeclub-master\nodeclub-master\proxy\topic.js:74:14) at Promise.<anonymous> (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\lib\promise.js:120:8) at Promise.EventEmitter.emit (events.js:95:17) at Promise.emit (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\lib\promise.js:59:38) at Promise.complete (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\lib\promise.js:70:20) at cb (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\lib\query.js:837:32) at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\lib\utils.js:408:16 at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:153:9 at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:193:11 at cb_callbackProxy (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\newrelic\lib\instrumentation\mongodb.js:57:37) at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\newrelic\node_modules\continuation-local-storage\context.js:76:17 at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:539:35 at Cursor.close (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:782:5) at Cursor.nextObject (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:539:17) at Cursor.wrappedNextObject [as nextObject] (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\newrelic\lib\instrumentation\mongodb.js:43:55) at [object Object].commandHandler (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:516:14) at [object Object].g (events.js:180:16) at [object Object].EventEmitter.emit (events.js:106:17) at Db._callHandler (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1439:25) at E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:425:30 at [object Object].MongoReply.parseBody (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:127:5) at [object Object].<anonymous> (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:384:22) at [object Object].EventEmitter.emit (events.js:95:17) at [object Object].<anonymous> (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:136:13) at [object Object].EventEmitter.emit (events.js:98:17) at Socket.<anonymous> (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:297:22) at Socket.EventEmitter.emit (events.js:95:17) at Socket.<anonymous> (stream_readable.js:745:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable (_stream_readable.js:407:10) at emitReadable (_stream_readable.js:403:5) at readableAddChunk (_stream_readable.js:165:9) at Socket.Readable.push (_stream_readable.js:127:10) at TCP.onread (net.js:528:21) at TCP.onread (E:\nodejs\nodeclub-master\nodeclub-master\node_modules\newrelic\node_modules\continuation-local-storage\node_modules\async-listener\glue.js:177:31)
根据你提供的错误信息,问题在于 NodeClub 应用在启动后尝试读取一个不存在的文件 E:\layout.html
。这个错误通常发生在试图渲染一个模板文件时,而该文件在指定路径中并不存在。
解决步骤:
-
检查路径: 首先确认
E:\layout.html
是否确实存在于指定路径中。如果文件不存在,你需要创建它或更改应用中的路径引用。 -
检查配置文件: 查看应用的配置文件,确保路径正确。这可能包括
app.js
或其他配置文件中与模板文件相关的路径设置。
示例代码及解释
假设 layout.html
是一个 EJS 模板文件,用于渲染页面布局。你可以按照以下步骤来解决这个问题:
步骤 1:检查路径
// app.js 或其他相关文件
const path = require('path');
// 确保路径正确
const layoutPath = path.join(__dirname, 'views', 'layout.html'); // 假设 views 文件夹在项目根目录下
console.log(layoutPath); // 打印路径以确认是否正确
步骤 2:检查模板引擎配置
确保你的应用正确配置了 EJS 模板引擎,并且路径指向正确的文件。
// app.js
const express = require('express');
const ejs = require('ejs');
const app = express();
// 设置视图引擎为 EJS
app.set('view engine', 'ejs');
// 设置视图文件夹路径
app.set('views', path.join(__dirname, 'views'));
app.get('/', (req, res) => {
res.render('index', { title: 'Home Page' });
});
app.listen(3000, () => {
console.log('NodeClub listening on port 3000 in development mode');
});
步骤 3:创建缺失的文件
如果 layout.html
确实不存在,你需要创建它。假设 views
文件夹结构如下:
project-root/
│
├── views/
│ ├── index.ejs
│ └── layout.html
└── app.js
创建 layout.html
文件:
<!-- views/layout.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= title %></title>
</head>
<body>
<%- body %>
</body>
</html>
通过以上步骤,你应该能够解决 ENOENT
错误,并使 NodeClub 应用正常运行。
好吧.自行解决了. 原来是故意出的个BUG. app.js 53行: app.locals._layoutFile = ‘/layout.html’; //绝对路径 改成 app.locals._layoutFile = ‘./layout.html’; //相对路径.
感谢,我也遇到这个问题了
Me too…
根据你提供的错误信息,“Error: ENOENT, no such file or directory 'E:\layout.html’”,可以推测出问题在于NodeClub试图加载一个名为layout.html
的文件,但该文件不存在于指定路径中。
解决方案
-
检查文件路径:
- 确认
layout.html
文件确实存在于项目目录中的正确位置。默认情况下,EJS模板引擎期望找到的layout.html
文件可能位于项目的某个视图目录中,例如views
目录。 - 如果文件确实存在,请确保路径配置正确。查看是否有硬编码的路径错误或相对路径错误。
- 确认
-
更新模板路径配置:
- 如果你的项目使用了Express框架,默认的视图引擎路径可能是
views/layout.ejs
而不是layout.html
。你可以修改渲染逻辑来指向正确的文件,或者将文件名改为.ejs
扩展名。 - 在启动服务器时,可以通过设置Express的
view engine
和views
路径来指定正确的视图目录:const express = require('express'); const path = require('path'); const app = express(); app.set('views', path.join(__dirname, 'views')); // 设置视图目录 app.set('view engine', 'ejs'); // 设置视图引擎为EJS // 假设你的布局文件在views目录下 app.get('/', (req, res) => { res.render('index', { title: 'Home' }); }); app.listen(3000, () => { console.log('App is running on port 3000'); });
- 如果你的项目使用了Express框架,默认的视图引擎路径可能是
-
确保依赖项已安装:
- 确保所有必需的npm包已正确安装。你可以运行
npm install
来安装项目所需的依赖包。
- 确保所有必需的npm包已正确安装。你可以运行
通过以上步骤,你应该能够解决“ENOENT, no such file or directory”的错误。如果问题仍然存在,请检查是否有其他硬编码的路径问题或者模板文件名的拼写错误。