按照官方快速入门教程执行到模板渲染部分时,出现错误:Can't find viewEngine for /Users/xxxi/egg-example/app/view/news/list.tpl
// config.default.js
’use strict';
module.exports = appInfo => {
const config = {};
// should change to your own
config.keys = appInfo.name + '_1490105333960_7282';
return config;
};
exports.view = {
defaultViewEngine: 'nunjucks',
mapping: {'.tpl': 'nunjucks'},
}
}
// plugin.js
’use strict’;
exports.nunjucks = {
enable: true,
package: 'egg-view-nunjucks'
};
配置写错了,你这样写 export.view 是不生效的。
bendise notifications@github.com于2017年3月25日 周六10:46写道:
>
- Node Version:6.9.2
- Egg Version:1.0.0
- Plugin Name:egg-view-nunjucks
- Plugin Version:2.0.0
- Platform:mac os
按照官方快速入门教程执行到模板渲染部分时,出现错误:Can't find viewEngine for
/Users/xxxi/egg-example/app/view/news/list.tplconfig.default.js
’use strict';module.exports = appInfo => {
const config = {};// should change to your own
config.keys = appInfo.name + '_1490105333960_7282';return config;
};exports.view = {
defaultViewEngine: 'nunjucks',mapping: {'.tpl': 'nunjucks'},};`plugin.js
’use strict’;// had enabled by egg
// exports.static = true;exports.nunjucks = {
enable: true,
package: 'egg-view-nunjucks'
};—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/eggjs/egg/issues/643, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWA1euhGXw1WIuGPboR0CpPGpdS-5Czks5rpIAVgaJpZM4Mo8DT
.
@bendise 可以看下 markdown 的语法,下次贴代码的时候,格式化下。
从你的代码来看,是这段的问题,
建议你看下 modules.exports 和 exports 的入门知识。
https://cnodejs.org/topic/54e67b70629934692ea99f91
module.exports = appInfo => {
const config = {};
// ...
return config;
}
exports.view = {
defaultViewEngine: 'nunjucks',
mapping: {'.tpl': 'nunjucks'},
}
应该改为:
module.exports = appInfo => {
const config = {};
// ...
config.view = {
// ...
}
return config;
}
@atian25 非常感谢耐心解答,已经解决了这个问题。
官网还没改过来,0.0
config.view
@alphaobj 改啥?
@alphaobj 官网的没问题。lz问题在于同时使用了 module.exports 和 exports 导致导出失败。统一使用前者(楼上 atian25 的例子)或者后者 (官网例子)都可以的。
@waitingsong 看 https://github.com/eggjs/egg/issues/2088
js 太灵活了,如果没有一个开发约定那么对于复制粘贴的新手来说很容易犯错。
所以…… 还是上 TS 吧。太爽了
TS 的今晚可以发布了
Most helpful comment
@bendise 可以看下 markdown 的语法,下次贴代码的时候,格式化下。
从你的代码来看,是这段的问题,
建议你看下 modules.exports 和 exports 的入门知识。
https://cnodejs.org/topic/54e67b70629934692ea99f91
应该改为: