Ember CLI fails in production

2019-07-18 05:27发布

I am deploying an Ember CLI app through jenkins and publishing it using nginx. Here is by jenkins build script:

npm install
bower install
node_modules/ember-cli/bin/ember build --environment=production

The nginx configuration simply directs sub.domain.com to jenkins\jobs\lastStable\archive\dist. That works fine, but when I go the page, it is blank and the following output in the console:

TypeError: Ember.Handlebars.compile is not a function   vendor-92ab6507ac60a5bf7c6819aa8fc418d6.js:18
ReferenceError: Swag is not defined   spa-client-9b01c6124f5b2a4cd2e95b62be7f5ba5.js:1

I am guessing that the two errors are related, but I can't figure out what is causing them. I have tried this answer to what appears to be a similar question, but it doesn't work for me. Everything works fine in my dev environment, and I can't see anything suspicious in the Brocfile.js.

3条回答
聊天终结者
2楼-- · 2019-07-18 06:04

Production uses handlebars-runtime which does not include Ember.Handlebars.compile. The reason is that it's smaller to use that in production and it's more effective to precompile which ember-cli does for you automatically.

Lots of discussion on the PR found here

查看更多
对你真心纯属浪费
3楼-- · 2019-07-18 06:23

I have same issue with one of third-party libraries I'm using.

I'm using this solution: https://github.com/rwjblue/_____ember-cli-test/commit/1a26911def6f04a4badee94c8a62d8205258867b

My Brocfile.js diff:

-var app = new EmberApp();
+var app = new EmberApp({
+  vendorFiles: {
+    'handlebars.js': {
+      production: 'bower_components/handlebars/handlebars.js'
+    }
+  }
+});
查看更多
男人必须洒脱
4楼-- · 2019-07-18 06:27

I encountered this same problem with the bootstrap for ember package. The temporary solution (from GH) was to inlcude the entire handlebars.js file in production:

var fileMover   = require('broccoli-file-mover');

var vendorTree = fileMover('vendor', {
    files: {
        'handlebars/handlebars.js': 'handlebars/handlbars.runtime.js'
    }
});

var app = new EmberApp({
    vendorFiles: {
        'handlebars.js': {
            production:  'vendor/handlebars/handlebars.min.js'
    }
   }
});
查看更多
登录 后发表回答