Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按照官网快速开始教程遇到错误,模板渲染问题 #643

Closed
bendise opened this issue Mar 25, 2017 · 9 comments
Closed

按照官网快速开始教程遇到错误,模板渲染问题 #643

bendise opened this issue Mar 25, 2017 · 9 comments

Comments

@bendise
Copy link

bendise commented Mar 25, 2017

按照官方快速入门教程执行到模板渲染部分时,出现错误: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'
};
@popomore
Copy link
Member

popomore commented Mar 25, 2017 via email

@atian25
Copy link
Member

atian25 commented Mar 25, 2017

@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 atian25 closed this as completed Mar 25, 2017
@bendise
Copy link
Author

bendise commented Mar 25, 2017

@atian25 非常感谢耐心解答,已经解决了这个问题。

@alphaobj
Copy link

官网还没改过来,0.0
config.view

@atian25
Copy link
Member

atian25 commented May 23, 2017

@alphaobj 改啥?

@waitingsong
Copy link
Contributor

@alphaobj 官网的没问题。lz问题在于同时使用了 module.exportsexports 导致导出失败。统一使用前者(楼上 atian25 的例子)或者后者 (官网例子)都可以的。

@atian25
Copy link
Member

atian25 commented Apr 4, 2018

@waitingsong#2088

@waitingsong
Copy link
Contributor

waitingsong commented Apr 4, 2018

js 太灵活了,如果没有一个开发约定那么对于复制粘贴的新手来说很容易犯错。
所以…… 还是上 TS 吧。太爽了

@atian25
Copy link
Member

atian25 commented Apr 4, 2018

TS 的今晚可以发布了

#2272

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants