【问题标题】:Error: XHR error (404 Not Found) after installing typescript-collection with Angular 2 final错误:使用 Angular 2 final 安装 typescript-collection 后出现 XHR 错误(404 Not Found)
【发布时间】:2016-09-26 16:25:23
【问题描述】:

在一个 Angular 2 快速启动项目中,我只是以这种方式安装了 typescript-collections:

npm install typescript-collections --save

我在启动项目后确实遇到了以下错误。

GET http://localhost:63342/IMA%20Sentinel/node_modules/typescript-collections 404 (Not Found)
Error: Error: XHR error (404 Not Found) loading http://localhost:63342/IMA%20Sentinel/node_modules/typescript-collections
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:63342/IMA%20Sentinel/node_modules/zone.js/dist/zone.js:636:29)
        at ZoneDelegate.invokeTask (http://localhost:63342/IMA%20Sentinel/node_modules/zone.js/dist/zone.js:225:37)
        at Zone.runTask (http://localhost:63342/IMA%20Sentinel/node_modules/zone.js/dist/zone.js:125:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:63342/IMA%20Sentinel/node_modules/zone.js/dist/zone.js:293:33)
    Error loading http://localhost:63342/IMA%20Sentinel/node_modules/typescript-collections as "typescript-collections" from http://localhost:63342/IMA%20Sentinel/app/history.service.js

这是我使用字典的 history.service.ts 文件

import { Injectable } from '@angular/core';
import { Dto } from './dto';
import Collections = require('typescript-collections');

@Injectable()
export class HistoryService {

  public managedDtoDico : Collections.Dictionary<number, Dto> = new Collections.Dictionary<number, Dto>();

软件包安装在这里: [项目名称]\node_modules\typescript-collections

我的 tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

我错过了什么吗?

更新:这里是 systemjs.config.js:

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(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',
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
      'typescript-collections': 'npm:typescript-collections'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular2-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

【问题讨论】:

  • 你能分享一下你的systemjs.config.js吗?

标签: angular typescript npm installation http-status-code-404


【解决方案1】:

好的,我明白了,这是 system.config.js 中缺少的内容:

  ,
  'typescript-collections': {
    main: './dist/lib/index.js',
    defaultExtension: 'js'
  }

现在可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-16
    • 2017-09-03
    • 2019-06-09
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 2017-07-09
    • 2018-07-19
    相关资源
    最近更新 更多