错误"Reflect.defineMetadata";在尝试加载瞬态网络工作者时 [英] Error "Reflect.defineMetadata" while trying to load a transient web worker
问题描述
我正在尝试从网络工作人员内部加载aurelia框架,以将工作人员装饰为临时人员.这是工作程序加载器:
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');
System.config({
defaultJSExtensions: true,
transpiler: 'none',
paths: {
'npm:*': '/jspm_packages/npm/*'
},
map: {
'aurelia-framework': 'npm:aurelia-framework@1.0.0-rc.1.0.1',
'aurelia-dependency-injection': 'npm:aurelia-dependency-injection@1.0.0-rc.1.0.0',
'aurelia-binding': 'npm:aurelia-binding@1.0.0-rc.1.0.2',
'aurelia-metadata': 'npm:aurelia-metadata@1.0.0-rc.1.0.0',
'aurelia-templating': 'npm:aurelia-templating@1.0.0-rc.1.0.0',
'aurelia-loader': 'npm:aurelia-loader@1.0.0-rc.1.0.0',
'aurelia-task-queue': 'npm:aurelia-task-queue@1.0.0-rc.1.0.0',
'aurelia-pal': 'npm:aurelia-pal@1.0.0-rc.1.0.0',
'aurelia-path': 'npm:aurelia-path@1.0.0-rc.1.0.0',
'aurelia-logging': 'npm:aurelia-logging@1.0.0-rc.1.0.0',
'aurelia-polyfills': 'npm:aurelia-polyfills@1.0.0-rc.1.0.0',
'aurelia-fetch-client': 'npm:aurelia-fetch-client@1.0.0-rc.1.0.0/aurelia-fetch-client'
}
});
System.import('files-service')
.then(module => {
let fs = new module.FilesService();
});
这是我声明工人阶级的方式:
Here is how I declare the worker class:
@transient()
export class FilesService {
constructor() {
httpClient = new HttpClient();
// rest of stuff
}
}
我得到了这个错误:
Uncaught (in promise) Error: Reflect.defineMetadata is not a function
at Object.define (http://localhost:9000/jspm_packages/npm/aurelia-metadata@1.0.0-rc.1.0.0/aurelia-metadata.js:49:15)
at eval (http://localhost:9000/jspm_packages/npm/aurelia-dependency-injection@1.0.0-rc.1.0.0/aurelia-dependency-injection.js:245:33)
at execute (http://localhost:9000/dist/files-service.js:93:67)
at u (http://localhost:9000/jspm_packages/system.js:5:97)
at Object.execute (http://localhost:9000/jspm_packages/system.js:5:3188)
at y (http://localhost:9000/jspm_packages/system.js:4:9948)
at w (http://localhost:9000/jspm_packages/system.js:4:10327)
at p (http://localhost:9000/jspm_packages/system.js:4:8205)
at h (http://localhost:9000/jspm_packages/system.js:4:8590)
at http://localhost:9000/jspm_packages/system.js:4:6896
Error loading http://localhost:9000/dist/files-service.js
任何主意可能有什么问题吗?顺便说一句,如果未将worker声明为暂时的,则没有问题(在这种情况下,不需要所有这些映射).
Any idea what might be wrong? BTW, if the worker is not declared as transient, there is no problem (in that case all these mappings are not required).
推荐答案
将aurelia-pal-browser
包添加到您的SystemJS映射中,然后将代码更新为以下内容:
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_assignment
let fs = new FilesService();
});
您似乎想在工作人员中使用该容器-这是一个示例:
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 = new Container())
// use the container...
.then(() => System.import('files-service')
.then(({ FilesService }) => {
let fs = container.get(FilesService);
});
这篇关于错误"Reflect.defineMetadata";在尝试加载瞬态网络工作者时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!