Egg: Can't find viewEngine for /.../app/view/index.tpl

Created on 25 Feb 2017  ·  18Comments  ·  Source: eggjs/egg

  • Node Version: 7.6.0
  • Egg Version: 1.0.0-rc.1
  • Plugin Name: egg-view-nunjucks
  • Plugin Version: 2.0.0
  • Platform: macOS 10.12.3

My configs

// {app_root}/config/plugin.js
exports.nunjucks = {
  enable: true,
  package: 'egg-view-nunjucks',
};
exports.view = {
  defaultViewEngine: 'nunjucks',
  mapping: {
    '.tpl': 'nunjucks',
  },
};

Most helpful comment

module.exports = appInfo => {
  const config = {};

  config.keys = appInfo.name + '_1493400288522_208';
  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.tpl': 'nunjucks',
    },
  };

  return config;
};

这样写就好了

All 18 comments

检查你的代码, 在哪里调用 app.viewEngine 了, 1.0.0 里面已经移除这个了, 改为 app.nunjucks

我从头到尾都是照着开源的文档配置的,没用过这个…

写错配置…

看下调用栈, 查下哪有有这个关键词, 是不是其他插件里面用到了

@geekdada 怎么解决的?我也遇到这个报错了

AssertionError: Can't find viewEngine for /Users/johnnychq/workbench/cxinscn_cathay_portal/private/app/view/home/index.nj
    at ContextView.[contextView#render] (/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.1.0.0@egg-view/lib/context_view.js:69:5)
    at next (native)
    at onFulfilled (/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.4.6.0@co/index.js:65:19)
    at process._tickCallback (internal/process/next_tick.js:103:7)

检查你的config目录是放在项目根目录的,不是app下。

李一航
Roy Li

On Feb 28, 2017, 2:19 AM +0800, johnnychen notifications@github.com, wrote:
>

@geekdada (https://github.com/geekdada) 怎么解决的?我也遇到这个报错了

AssertionError: Can't find viewEngine for /Users/johnnychq/workbench/cxinscn_cathay_portal/private/app/view/home/index.nj at ContextView.[contextView#render] (/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.1.0.0@egg-view/lib/context_view.js:69:5) at next (native) at onFulfilled (/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.4.6.0@co/index.js:65:19) at process._tickCallback (internal/process/next_tick.js:103:7)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (https://github.com/eggjs/egg/issues/455#issuecomment-282803841), or mute the thread (https://github.com/notifications/unsubscribe-auth/ADH4YkW3QP2z6deOXrYkiEYtsKdYxVisks5rgxObgaJpZM4ML9A0).

看看应用目录的 run/config_application.json 的配置是否正确
Roy Li notifications@github.com于2017年2月28日 周二09:05写道:

检查你的config目录是放在项目根目录的,不是app下。

李一航
Roy Li

On Feb 28, 2017, 2:19 AM +0800, johnnychen notifications@github.com,
wrote:
>

@geekdada (https://github.com/geekdada) 怎么解决的?我也遇到这个报错了

AssertionError: Can't find viewEngine for
/Users/johnnychq/workbench/cxinscn_cathay_portal/private/app/view/home/index.nj
at ContextView.[contextView#render]
(/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.1.0.0@egg-view/lib/context_view.js:69:5)
at next (native) at onFulfilled
(/Users/johnnychq/workbench/cxinscn_cathay_portal/private/node_modules/.4.6.0@co/index.js:65:19)
at process._tickCallback (internal/process/next_tick.js:103:7)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
https://github.com/eggjs/egg/issues/455#issuecomment-282803841), or mute
the thread (
https://github.com/notifications/unsubscribe-auth/ADH4YkW3QP2z6deOXrYkiEYtsKdYxVisks5rgxObgaJpZM4ML9A0
).


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/455#issuecomment-282908714, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAWA1SBXKCGr-pOzPUFCRczdwLryWAU5ks5rg3K9gaJpZM4ML9A0
.

检查了,

  • config目录跟app是同级的
  • run/config_application.json 是自动生成的,截图如下

image

@johnnychen 不是看这个 key, 这个是 plugins.nunjucks, 要看 config.viewconfig.nunjucks

@atian25 config/plugin.js 我是按照egg-view-nunjucks官方配置的

 exports.nunjucks = {
   enable: true,
   package: 'egg-view-nunjucks',
 };

 exports.view = {
   defaultViewEngine: 'nunjucks',
   mapping: {
     '.nj': 'nunjucks',
   },
 };
 exports.view = {
   defaultViewEngine: 'nunjucks',
   mapping: {
     '.nj': 'nunjucks',
   },
 };

这个是放在 config/config.default.js 里的

-_- 谢谢

这个很坑啊,因为egg-init的simple模板里有这下面这个

module.exports = appInfo => {
  const config = {}

  // should change to your own
  config.keys = appInfo.name + '_1492679669188_8695'

  return config
}

这样你不管在下面加什么都得出错,只能加到中间,或者改掉这上面的

@yangg 这是 Node 的基础知识来着,我觉得不算坑。

@yangg 这是基础知识

这知识我知道,但是这个模版坑,按着文档来,结果出不来
On Thu, Apr 20, 2017 at 6:36 PM Hengfei Zhuang notifications@github.com
wrote:

@yangg https://github.com/yangg 这是基础知识


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/eggjs/egg/issues/455#issuecomment-295675721, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAY-id9i0qBq6zx_3I5mrOh4EJd7PMNcks5rxzU7gaJpZM4ML9A0
.

module.exports = appInfo => {
  const config = {};

  config.keys = appInfo.name + '_1493400288522_208';
  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.tpl': 'nunjucks',
    },
  };

  return config;
};

这样写就好了

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bupafengyu picture bupafengyu  ·  3Comments

popomore picture popomore  ·  3Comments

lvgg3271 picture lvgg3271  ·  3Comments

Seovos picture Seovos  ·  3Comments

zhaofinger picture zhaofinger  ·  3Comments