ember-cli / ember-fetch

HTML5 fetch polyfill from github wrapped and bundled for ember-cli users.
MIT License
175 stars 80 forks source link

FastBoot is not defined from Browser Console #69

Open majew7 opened 7 years ago

majew7 commented 7 years ago

I see the following error in my browser console:

Error in Component#send ReferenceError: FastBoot is not defined

Though this cannot be correct, as our Ember Application is NOT FastBoot enabled.

Culprit? Also in Chrome Dev Tools - Sources I see a file named: fastboot-fetch.js

(function() {
  define('fetch', ['exports'], function(self) {
    var fetch = FastBoot.require('node-fetch');
    self['default'] = fetch;
    self['Headers'] = fetch.Headers;
    self['Request'] = fetch.Request;
    self['Response'] = fetch.Response;
  });

  define('fetch/ajax', ['exports'], function() {
    throw new Error('You included `fetch/ajax` but it was renamed to `ember-fetch/ajax`');
  });
})();

Our Context We have not explicitly installed this ember-fetch package. Rather ember-fetch is a dependency upon ember-simple-auth, which we have explicitly npm installed.

We are using Ember Engines with lazyLoading enabled.

Similar Issue The GitHub Repo ember-cli-moment-shim had a similar issue: Issue: https://github.com/jasonmit/ember-cli-moment-shim/issues/145 Fix: https://github.com/jasonmit/ember-cli-moment-shim/commit/591ae7a3c164df8023838d4f04e20c98583b555c

jasonmit commented 6 years ago

I also ran into this using ember-fetch. Here is my current work around.

Warning: not public API by any means and very likely will break in the future

// my-engine/index.js
module.exports = EngineAddon.extend({
  name: 'my-engine',

  lazyLoading: {
    enabled: true
  },

  included() {
    this._super.included.apply(this, arguments);

    const engines = this.project.findAddonByName('ember-engines');
    engines.manifestOptions.filesToIgnore.push(/\/fastboot-fetch.js$/);
  },

  isDevelopingAddon() {
    return true;
  }
})

The true fix is likely https://github.com/ember-engines/ember-engines/issues/490#issuecomment-334976982 but some discussion needs to happen before that can be resolved. Specifically around how the options are provided to ember-engines from the app engine(s).

Edit: Reproduction of the issue https://github.com/jasonmit/x-lazy-app/