ReferenceError: setTimeout is not defined in ember-template-compiler-3.1.1.js



We are migrating from Ember 2.x to Ember 3.x (3.1.1 for now). We have been using MSIE JavaScript Engine to precompile templates, and it works great with Ember 2.x;

Now There is a problem when we precompile templates with ember-template-compiler-3.1.1.js. It is now using the global setTimeout() function which is not available in JavaScript engines. And so, script engine throws when it tries to execute ember-template-compiler-3.1.1.js file.

'Script threw an exception: 'setTimeout' is undefined'

ReferenceError: setTimeout is not defined
    at ember-template-compiler-3.1.1-.js:4355:23 ->     var SET_TIMEOUT = setTimeout;
    at internalRequire (ember-template-compiler-3.1.1-.js:62:16)
    at internalRequire (ember-template-compiler-3.1.1-.js:58:24)
    at internalRequire (ember-template-compiler-3.1.1-.js:58:24)
    at requireModule (ember-template-compiler-3.1.1-.js:95:14)
    at ember-template-compiler-3.1.1-.js:17908:92
    at ember-template-compiler-3.1.1-.js:17911:2

I wonder is that configurable. i.e can we switch setTimeout() implementation to work with JavaScript engines? And, what is the problem with the old implementation of setTimeout()?



The engine you are using to compile with doesn’t have a setTimeout?


This code is part of Backburner.js which is included in ember-template-compiler.js to satisfy imports (which would error if not present) but it essentially unused during template compilation.

Newer versions of Ember do not include this code in their ember-template-compiler.js (at least 3.3.0-beta.1, but possibly 3.2.0).


Thanks for the replies, @rwjblue

Yes, the engine we are using to precompile with doesn’t have a setTimeout. It’s MSIE Script Engine. And the other engines I have tested are V8, Chakra, Jurassic, EdgeJS. They all throw that exception. Everyone says setTimeout is not part of ES6 specification, so it is not implemented into script engines. I also have tried PhantomJS but it has a problem with weakmap.

So, I guess we will have to skip a few versions and wait for the stable version of Ember 3.2.0.

Thanks, And also big thanks to the awesome Ember Collection component. :smiley: