Skip to content Skip to sidebar Skip to footer

Error "reflect.definemetadata" While Trying To Load A Transient Web Worker

I am trying to load the aurelia framework from inside a web worker in order to decorate the worker as transient. Here is the worker loader: importScripts('/jspm_packages/system.js'

Solution 1:

Add the aurelia-pal-browser package to your SystemJS map, then update your code to something like this:

// Import Aurelia's [p]latform [a]bstraction [l]ibrary for the browser.// The PAL does some basic feature detection and serves as an abstraction for// browser globals.System.import('aurelia-pal-browser')
  .then(pal => pal.initialize())
  // now import a small set of polyfills for things like Reflect.defineMetadata
  .then(() =>System.import('aurelia-polyfills'))
  // now you should be all set...
  .then(() =>System.import('files-service')
  .then(({ FilesService }) => {  // <-- look how fancy I am! ES6 destructuring FTW - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignmentlet fs = newFilesService();
  });

It looks like you want to use the container in your worker though- here's an example:

let container = null;

System.import('aurelia-pal-browser')
  .then(({ initialize }) =>initialize())
  .then(() =>System.import('aurelia-polyfills'))
  // import DI and instantiate a container for the worker to use.
  .then(() =>System.import('aurelia-dependency-injection'))
  .then(({ Container }) => container = newContainer())
  // use the container...
  .then(() =>System.import('files-service')
  .then(({ FilesService }) => {
    let fs = container.get(FilesService);
  });

Post a Comment for "Error "reflect.definemetadata" While Trying To Load A Transient Web Worker"