javascript - express中加载css和js时候出现500错误
PHP中文网
PHP中文网 2017-04-11 12:18:15
[JavaScript讨论组]

启动时候不报错,浏览器访问的时候报错,layout.jade加载出来了,但是index.jade和css,js文件都没加载出来,报500错误,`

Cannot read property 'lazyrouter' of undefined

TypeError: Cannot read property 'lazyrouter' of undefined
at route (C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\application.js:254:7)
at Layer.handle [as handle_request] (C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\router\index.js:312:13)
at C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\router\index.js:280:7
at Function.process_params (C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\router\index.js:330:12)
at next (C:\Users\Dell\Desktop\express\microblog\node_modules\express\lib\router\index.js:271:10)
at C:\Users\Dell\Desktop\express\microblog\node_modules\express-session\index.js:489:7
at C:\Users\Dell\Desktop\express\microblog\node_modules\connect-mongo\lib\connect-mongo.js:306:11
at handleCallback (C:\Users\Dell\Desktop\express\microblog\node_modules\mongodb\lib\utils.js:96:12)
at C:\Users\Dell\Desktop\express\microblog\node_modules\mongodb\lib\collection.js:1335:5`

静态文件路径

app.use(express.static(__dirname+'/public'));

页面引用路径

link(type='text/css',rel='stylesheet', href='/stylesheets/bootstrap.css')
link(type='text/css',rel='stylesheet', href='/stylesheets/bootstrap-responsive.css')
script(src="/javascripts/jquery.js")
script(src="/javascripts/bootstrap.js")
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(3)
怪我咯

没有读写权限吧

高洛峰

__dirname+'/public'输出下看看。

用这个试试呢

const path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
PHP中文网

这里报的错是lazyrouter未定义,跟静态文件路径应该没问题。
我估计是你用lazyrouter的时候错了

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

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