尝试在expressJS应用程序中使用haml咖啡时出现奇怪错误
Strange errors trying to use haml-coffee with an expressJS app
这是我的app.js
文件,遵循haml咖啡指南:
// misc requirements
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path');
// setup app
var app = express();
// set default engine to haml-coffee
app.engine( 'hamlc', require('haml-coffee'.__express ));
// configure misc stuff
app.configure(function(){
app.set('port', process.env.PORT || 3000); // set localhost port to 3000
app.set('views', __dirname + '/views'); // setup views (templates)
app.set('view engine', 'hamlc'); // use haml-coffee as default templating engine
app.set('title', 'Learn Some Code'); // set the website title
app.use(express.favicon()); // favicon handling
app.use(express.logger('dev')); // logging
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router); // use the router
app.use(express.static(path.join(__dirname, 'public')));
});
// only configure this for development
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
但是当我运行node app.js
时。。。我得到一个奇怪的错误:
module.js:236
var start = request.substring(0, 2);
^
TypeError: Cannot call method 'substring' of undefined
at Function.Module._resolveLookupPaths (module.js:236:23)
at Function.Module._resolveFilename (module.js:328:31)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/Users/chris/src/learnsomecode/app.js:11:22)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
您的需求中有一个轻微的拼写错误。更改
app.engine( 'hamlc', require('haml-coffee'.__express ));
至
app.engine( 'hamlc', require('haml-coffee').__express );
'haml-coffee'.__express
解析为undefined
,使require(undefined)
抛出Cannot call method 'substring' of undefined
错误。
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 尝试在expressJS应用程序中使用haml咖啡时出现奇怪错误
- 更新:用户错误-TYPO!!grunt contrib咖啡错误查找文件&写入目的地
- 我的基于节点的咖啡脚本未运行(错误%1不是有效的应用程序.)
- JS2咖啡投掷找不到模块错误
- 咖啡脚本变量声明放在错误的位置
- 咖啡脚本中的承诺.尝试将多个参数传递给“then”时出现“意外逗号”错误
- 哈姆尔咖啡 ie8 错误
- 咖啡脚本错误编译
- 这是一个列表理解泄漏咖啡脚本中变量名称的错误吗?
- ROR-咖啡脚本导致“;未捕获引用错误”;
- rails服务器/控制台错误-没有这样的文件可加载-咖啡脚本(LoadError)