无法将nib包含到我的expressjs / nodejs站点?

时间:2011-11-17 18:24:15

标签: node.js express nib

我按照示例here将笔尖添加到我的网站:

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , nib = require('nib');

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser());
  app.use(express.session({ secret: 'your secret here' }));
  app.use(require('stylus').middleware({ src: __dirname + '/public' }));
  app.use(nib());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

但是当我启动服务器时,我收到了这个错误:

500 TypeError: Object #<IncomingMessage> has no method 'include'
at Object.handle (/home/alex/apps/foo/node_modules/nib/lib/nib.js:51:11)
at next (/home/alex/apps/foo/node_modules/express/node_modules/connect/lib/http.js:201:15)
at Object.handle (/home/alex/apps/foo/node_modules/stylus/lib/middleware.js:187:7)
at next (/home/alex/apps/foo/node_modules/express/node_modules/connect/lib/http.js:201:15)
at /home/alex/apps/foo/node_modules/express/node_modules/connect/lib/middleware/session.js:323:9
at /home/alex/apps/foo/node_modules/express/node_modules/connect/lib/middleware/session.js:342:9
at Array.0 (/home/alex/apps/foo/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:52:9)
at EventEmitter._tickCallback (node.js:126:26)

有任何解决此问题的建议吗?

1 个答案:

答案 0 :(得分:0)

在“开发”模式下尝试此操作,因为您不希望在生产环境中的运行时进行手写笔编译:

app.configure('development', function(){
  var stylusMiddleware = stylus.middleware({
  src: __dirname + '/stylus/', // .styl files are located in `/stylus`
  dest: __dirname + '/public/', // .styl resources are compiled `/css/*.css`
  debug: true,
  compile: function(str, path) { // optional, but recommended
    return stylus(str)
      .set('filename', path)
      .set('warn', true)
      .set('compress', true)
      .use(nib());
    }
  });
  app.use(stylusMiddleware);  
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

app.configure('production', function(){
  app.use(express.errorHandler());
});

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express['static'](__dirname + '/public'));
});

这是我通常使用笔尖和手写笔的设置。通过此设置,您需要将require("stylus")向上移动到stylus = require("stylus"),与require("nib")类似。

您必须在configure之后获得常规development方法列表。