尝试使我的nativescript应用程序在启用时运行。使用最新版本的nativescript,它构建得很好。启动应用程序时,错误Reflect.getMetadata is not a function
显示,应用程序不起作用。当使用依赖于Reflect.getMetadata的依赖项时会发生这种情况,例如:https://github.com/ghidoz/angular2-jsonapi
演示项目使用aot:https://github.com/annervisser/nativescript-aot-error时出错
应用程序使用JIT完美运行,并且仅在使用--env.aot
标志时中断。 Webpack始终启用,因为这是一个角度项目(总是使用--bundle
标志运行)
完整的堆栈跟踪:
System.err: TypeError: Reflect.getMetadata is not a function
System.err: File: "<unknown>, line: 1, column: 265
System.err:
System.err: StackTrace:
System.err: Frame: function:'saveAnnotations', file:'file:///data/data/nl.persistence.stubs/files/app/vendor.js', line: 78279, column: 36
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/vendor.js', line: 78322, column: 13
System.err: Frame: function:'module.exports../app/shared/models/user.model.ts.__decorate', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 2287, column: 110
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 2302, column: 5
System.err: Frame: function:'./app/shared/models/user.model.ts', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 2348, column: 2
System.err: Frame: function:'__webpack_require__', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 752, column: 30
System.err: Frame: function:'fn', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 122, column: 20
System.err: Frame: function:'./app/shared/auth/auth.service.ts', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 1355, column: 76
System.err: Frame: function:'__webpack_require__', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 752, column: 30
System.err: Frame: function:'fn', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 122, column: 20
System.err: Frame: function:'./app/shared/auth/auth-interceptor.service.ts', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 1280, column: 71
System.err: Frame: function:'__webpack_require__', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 752, column: 30
System.err: Frame: function:'fn', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 122, column: 20
System.err: Frame: function:'./app/app.module.ngfactory.js', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 1041, column: 96
System.err: Frame: function:'__webpack_require__', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 752, column: 30
System.err: Frame: function:'fn', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 122, column: 20
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 2387, column: 83
System.err: Frame: function:'./main.ts', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 2465, column: 30
System.err: Frame: function:'__webpack_require__', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 752, column: 30
System.err: Frame: function:'checkDeferredModules', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 45, column: 23
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 828, column: 18
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/bundle.js', line: 831, column: 10
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/nl.persistence.stubs/files/app/starter.js', line: 2, column: 1
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err:
System.err: at com.tns.Runtime.runModule(Native Method)
System.err: at com.tns.Runtime.runModule(Runtime.java:624)
System.err: at com.tns.Runtime.run(Runtime.java:616)
System.err: at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
System.err: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
我尝试在不同的地方导入反射元数据,包括polyfills.ts
,main.tns.ts
,app.module.tns.ts
我也尝试将它包含在我的webpack / tnsconfig中,并将目标更改为es2015或es6。这些都没有任何区别。
搜索此错误会导致很多角度的一般信息,建议将reflect-metadata
的导入添加到polyfills.ts
。这没有用。
在app模块的顶部添加reflect-metadata
包的import语句(基本上在访问JsonApiDatastoreConfig
装饰器之前)。
import "reflect-metadata";