Skip to content

Fastboot incompatible with modern state of the ecosystem #913

Open
@runspired

Description

@runspired

Issues:

  • Expected globals are not present, such as fetch, Headers ReadableStream etc.
  • buildSandboxGlobal no longer runs, so there is no way to enhance the built in globals with WHATWG spec implementations of APIs such as AbortController and fetch even when these things exist as globals in node. (this turned out to be a config mishap for ember-cli-fastboot-testing see Config not working embermap/ember-cli-fastboot-testing#488)
  • fastbootDependencies does not allow whitelisting local dependencies, which prevents applications from addressing this shortcoming short of using pnpm patch to splice in new globals. For instance the following fails to resolve with Fastboot.require
{
  "dependencies":  {
     "fastboot-abort-controller": "file:./fastboot-overrides/abort-controller"
  },
  "fastbootDependencies": [
     "fastboot-abort-controller",
  ]
}

Example recommended config for use with EmberData and fetch

/* global ReadableStream, WritableStream, TransformStream */
module.exports = function (environment) {
  return {
    buildSandboxGlobals(defaultGlobals) {
      return Object.assign({}, defaultGlobals, {
        AbortController,
        fetch: fetch,
        ReadableStream:
          typeof ReadableStream !== 'undefined' ? ReadableStream : require('node:stream/web').ReadableStream,
        WritableStream:
          typeof WritableStream !== 'undefined' ? WritableStream : require('node:stream/web').WritableStream,
        TransformStream:
          typeof TransformStream !== 'undefined' ? TransformStream : require('node:stream/web').TransformStream,
        Headers: typeof Headers !== 'undefined' ? Headers : undefined,
      });
    },
  };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions