adopted-ember-addons / ember-burger-menu

An off-canvas sidebar component with a collection of animations and styles using CSS transitions
https://adopted-ember-addons.github.io/ember-burger-menu/
MIT License
279 stars 48 forks source link

FastBoot compat #117

Closed noslouch closed 6 years ago

noslouch commented 6 years ago

Starting a new app and using the template provided in the docs throws an error in FastBoot:

There was an error running your app in fastboot. More info about the error:
 ReferenceError: Element is not defined
    at eval (webpack://__ember_auto_import__/../ember-burger-menu/node_modules/matches-selector/index.js?:6:13)
    at Object.../ember-burger-menu/node_modules/matches-selector/index.js (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor.js:90226:1)
    at __webpack_require__ (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor.js:90139:30)
    at eval (webpack://__ember_auto_import__/../ember-burger-menu/node_modules/closest/index.js?:1:15)
    at Object.../ember-burger-menu/node_modules/closest/index.js (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor.js:90215:1)
    at __webpack_require__ (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor.js:90139:30)
    at Module.eval [as callback] (webpack://__ember_auto_import__/./tmp/ember_auto_import_webpack-staging_dir-9qB0145l.tmp/app.js?:16:42)
    at Module.exports (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:106:1)
    at Module._reify (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:143:1)
    at Module.reify (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:130:1)
    at Module.exports (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:104:1)
    at Module._reify (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:143:1)
    at Module.reify (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:130:1)
    at Module.exports (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:104:1)
    at requireModule (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/vendor/loader/loader.js:27:1)
    at Class._extractDefaultExport (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/addon-tree-output/ember-resolver/resolvers/classic/index.js:408:1)
    at Class.resolveOther (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/addon-tree-output/ember-resolver/resolvers/classic/index.js:110:1)
    at Class.superWrapper (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-utils.js:428:1)
    at Class.resolve (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-application/system/resolver.js:133:1)
    at _resolve (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/container.js:885:1)
    at Registry.resolve (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/container.js:588:1)
    at Registry.resolve (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/container.js:592:1)
    at Container.factoryFor (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/container.js:144:1)
    at Class.factoryFor (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-runtime/mixins/container_proxy.js:45:1)
    at Class.componentFor (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-views/component_lookup.js:9:1)
    at lookupComponentPair (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-views/utils/lookup-component.js:34:1)
    at lookupComponent (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-views/utils/lookup-component.js:53:1)
    at RuntimeResolver._lookupComponentDefinition (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:7227:1)
    at RuntimeResolver.lookupComponentDefinition (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:7138:1)
    at CompileTimeLookup.lookupComponentDefinition (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:5049:1)
    at refineBlockSyntax (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:6990:1)
    at Blocks.compile (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/opcode-compiler.js:355:1)
    at /Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/opcode-compiler.js:203:1
    at Compilers.compile (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/opcode-compiler.js:40:1)
    at CompilableTemplateImpl.compile (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/opcode-compiler.js:810:1)
    at OutletComponentManager.getLayout (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:3641:1)
    at Object.evaluate (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:1287:1)
    at AppendOpcodes.evaluate (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:44:1)
    at LowLevelVM.evaluateSyscall (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:2755:1)
    at LowLevelVM.evaluateInner (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:2731:1)
    at LowLevelVM.evaluateOuter (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:2723:1)
    at VM.next (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:4802:1)
    at TemplateIteratorImpl.next (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/@glimmer/runtime.js:4883:1)
    at RootState.render (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4556:1)
    at TransactionRunner.runInTransaction (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-metal.js:1231:1)
    at InertRenderer._renderRoots (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4822:1)
    at InertRenderer._renderRootsTransaction (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4854:1)
    at InertRenderer._renderRoot (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4787:1)
    at InertRenderer._appendDefinition (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4712:1)
    at InertRenderer.appendOutletView (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/ember-glimmer.js:4700:1)
    at invokeWithOnError (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/backburner.js:216:1)
    at Queue.flush (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/backburner.js:125:1)
    at DeferredActionQueues.flush (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/backburner.js:278:1)
    at Backburner.end (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/backburner.js:410:1)
    at Timeout.Backburner._boundAutorunEnd [as _onTimeout] (/Users/bwhitton/src/foo/tmp/broccoli_merge_trees-output_path-Ff6W8yJR.tmp/assets/backburner.js:372:1)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)

Specifically this line from the matches-selector package, which is a required by closest:

var proto = typeof Element !== 'undefined' ? Element.prototype : {};

Which is intended to run in a browser environment only. I'm not exactly sure how, but can you wrap that closest import so that it only runs in fastboot land? This is a problem with the import, not the run-time code in this project. But I think it can be solved with a build-time adjustment.

noslouch commented 6 years ago

EDIT: that line from above is actually from a newer version of matches-selector. The line in the version of matches-selector that closest specifies is actually this:

var proto = Element.prototype;

118 ups the version of matches-selector to use the node-safe version of that line.