javascript - Express包报错
ringa_lee
ringa_lee 2017-04-11 10:06:46
[JavaScript讨论组]
  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)
ringa_lee
ringa_lee

ringa_lee

全部回复(2)
天蓬老师

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

module.exports = router;

天蓬老师

路由你得 .use 一个中间件

栗子

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号