无法将 nib 包含到我的 expressjs/nodejs 站点中?
Posted
技术标签:
【中文标题】无法将 nib 包含到我的 expressjs/nodejs 站点中?【英文标题】:Failed to include nib to my expressjs/nodejs site? 【发布时间】:2011-11-17 18:24:15 【问题描述】:我按照示例 here 将 nib 添加到我的网站:
/**
* 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】:在您的“开发”模式下尝试此操作,因为您不希望在生产环境中在运行时编译手写笔:
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")
。
你必须在development
之后有你的一般configure
方法列表。
【讨论】:
以上是关于无法将 nib 包含到我的 expressjs/nodejs 站点中?的主要内容,如果未能解决你的问题,请参考以下文章
自定义单元格导致“NSInternalInconsistencyException”,原因:“无法在包中加载 NIB:
无法将 vue 相关的 npm 包包含到我的 Laravel + Vue 项目中