Willem de Wit
Willem de Wit

Reputation: 8732

Use ember-i18n with ember-cli production environment

I run into an issue where ember-i18n can be used with an ember-cli server running in development environment. But when I set --environment production I get the following error:

Error: The default Ember.I18n.compile function requires the full Handlebars. Either include the full Handlebars or override Ember.I18n.compile.

The error occurres because ember-cli includes Handlebars-production on production environment. Is there a solution for this problem?

I think I need to precompile the translations.

Upvotes: 0

Views: 670

Answers (2)

Matt Beedle
Matt Beedle

Reputation: 171

There is no way to get around importing the full handlebars when using ember-i18n. You do not need to specify the same string import for development and production though. Just add this to your Brocfile:

    app.import('vendor/handlebars/handlebars.js');

I had exactly the same issue and this is the solution that Stefan Penner advised. https://github.com/stefanpenner/ember-cli/pull/675#issuecomment-47431195. Worked fine for me. One thing to note though, for some reason I had the import statement as the first import. When it was the last one it didn't seem to work. I didn't try anywhere in between though, or try to debug that issue.

Upvotes: 1

Willem de Wit
Willem de Wit

Reputation: 8732

One way to fix this is to configure ember-cli to include the full handlebars version on production:

app.import({
  development: 'vendor/handlebars/handlebars.js',
  production:  'vendor/handlebars/handlebars.js'
});

A drawback is that the (much) bigger library is included in the build, only for my translations. I keep looking for a way to precompile my translations.

Upvotes: 1

Related Questions