Express包报错

  1. 用express框架做了个小网站玩,之前都可以正常运行。今天做了一些简单的修改(但没碰任何框架自带的module),结果调试的时候框架自带包报错。 不知何处出了问题。报错代码如下,还望不吝指点。。

anzhendeMacBook-Air:www.niceandeasy.cn anzhen$ node bin/www
/Users/anzhen/git/www.niceandeasy.cn/node_modules/express/lib/router/index.js:458
throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));

  ^

TypeError: Router.use() requires middleware function but got a Object

at Function.use (/Users/anzhen/git/www.niceandeasy.cn/node_modules/express/lib/router/index.js:458:13)
at EventEmitter.<anonymous> (/Users/anzhen/git/www.niceandeasy.cn/node_modules/express/lib/application.js:219:21)
at Array.forEach (native)
at EventEmitter.use (/Users/anzhen/git/www.niceandeasy.cn/node_modules/express/lib/application.js:216:7)
at Object.<anonymous> (/Users/anzhen/git/www.niceandeasy.cn/app.js:40:5)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
阅读 6.4k
2 个回答

已解决,某个JS文件少了:

module.exports = router;

路由你得 .use 一个中间件

栗子

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题