ember-cli fails on --environment=production (Uncaught Error: Could not find module)

泄露秘密 提交于 2019-12-04 14:00:42
Daniel Kmak

Solution is mentioned on Ember CLI website:

This is somewhat non-standard and discouraged, but suppose that due to a requirement in your application that you need to use the full version of Handlebars even in the production environment.

Basically, you can pass vendorFiles option to your EmberApp instance which will force CLI to include full version of Handlebars.

Example of explicitly requiring handlebars.js , in Brocfile.js:

var app = new EmberApp({
  vendorFiles: {
    'handlebars.js': {
      production: 'bower_components/handlebars/handlebars.js'
    }
  }
});

This is recommended way of solving this issue(discussion on GitHub).

I had exact the same problem, and James_1x0 is correct, it is an broccoli issue. After debugging it occurs, that the "undefined" error apears on "Ember.handlebars.compile" which lead to other research. It seems, that in production envrironment "handlebars.js" is replaced by "handlebars.runtime.js" in the ember-cli build process, which seem to be a problem for broccoli at this time.

Other devs had the same problem but with other libraries as well: https://github.com/stefanpenner/ember-cli/pull/675#issuecomment-47431195

Here the solution was to add:

    var index = app.legacyFilesToAppend.indexOf('bower_components/handlebars/handlebars.runtime.js');
if(index) {
    app.legacyFilesToAppend[index] = 'bower_components/handlebars/handlebars.js';
}

into your Brocfile.js to replace the "handlebars.runtime.js" with the "handlebars.js". This also fixed the problem for me. It sure has the drawback that the whole handlebars file is deployed but its a workarround for now, until the problem is fixed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!