2

我正在使用 Angular2 和 Node.js 使用 ng2-File-Upload 进行文件上传,但是在运行我的项目时,我遇到了与 Reflect.getOwnMetadata 相关的错误,这是显示的错误:

在此处输入图像描述

这是我的 systemjs.config.js

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
      /** Path for ng2-file-upload */
      'ng2-file-upload' : 'npm:ng2-file-upload' 
      /** Path for ng2-file-upload */
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './transpiled-js/main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      /** Configuration for ng2-file-upload */
      'ng2-file-upload' : { 
        main: './ng2-file-upload.js',
        defaultExtension: 'js'
      }
      /** Configuration for ng2-file-upload */
    }
  });
})(this);
4

1 回答 1

0

这是我遇到完全相同的问题时的情况:

我有两个同名的 TypeScript 文件(比如FileUploadService.ts)位于两个不同的位置。一个用于处理服务器逻辑(位于server目录中),另一个public用于通过 Angular 服务上传文件的目录。

问题是我在使用包的位置导入了错误的服务ng2-file-upload,而这又取决于 Angular 模块——这些模块从未被导入。

这意味着Reflect.getOwnMetadata在 Typescript 编译期间,某处定义的文件不可用。

请确保您在正确的位置引用正确的文件,您也可能属于这种情况。

于 2017-11-12T08:51:18.490 回答