当前位置: 首页 > 知识库问答 >
问题:

(SystemJS)XHR错误@角/commobundles/common.umd.js/http未找到

左丘智渊
2023-03-14

我正在我的应用程序中发出一个简单的http请求

我正在使用Angular 2 Quickstart并将所有Angular软件包更新为4.3。4.

这是我的软件包。json


    {
      "name": "angular-quickstart",
      "version": "1.0.0",
      "description": "QuickStart package.json from the documentation, supplemented with testing support",
      "scripts": {
        "build": "tsc -p src/",
        "build:watch": "tsc -p src/ -w",
        "build:e2e": "tsc -p e2e/",
        "serve": "lite-server -c=bs-config.json",
        "serve:e2e": "lite-server -c=bs-config.e2e.json",
        "prestart": "npm run build",
        "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
        "pree2e": "npm run build:e2e",
        "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
        "preprotractor": "webdriver-manager update",
        "protractor": "protractor protractor.config.js",
        "pretest": "npm run build",
        "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
        "pretest:once": "npm run build",
        "test:once": "karma start karma.conf.js --single-run",
        "lint": "tslint ./src/**/*.ts -t verbose"
      },
      "keywords": [],
      "author": "",
      "license": "MIT",
      "dependencies": {
        "@angular/common": "4.3.4",
        "@angular/compiler": "4.3.4",
        "@angular/core": "4.3.4",
        "@angular/forms": "4.3.4",
        "@angular/http": "4.3.4",
        "@angular/platform-browser": "4.3.4",
        "@angular/platform-browser-dynamic": "4.3.4",
        "@angular/platform-server": "4.3.4",
        "@angular/router": "4.3.4",
        "angular-in-memory-web-api": "~0.3.0",
        "core-js": "^2.4.1",
        "rxjs": "^5.4.3",
        "systemjs": "0.19.40",
        "typescript": "2.4.2",
        "zone.js": "^0.8.16"
      },
      "devDependencies": {
        "concurrently": "^3.2.0",
        "lite-server": "^2.2.2",
        "typescript": "~2.1.0",
        "canonical-path": "0.0.2",
        "tslint": "^3.15.1",
        "lodash": "^4.16.4",
        "jasmine-core": "~2.4.1",
        "karma": "^1.3.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-jasmine": "^1.0.2",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~4.0.14",
        "rimraf": "^2.5.4",
        "@types/node": "^6.0.46",
        "@types/jasmine": "2.5.36"
      },
      "repository": {}
    }

这是我的系统。配置。js


    /**
     * System configuration for Angular 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',
          'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
          app: {
            defaultExtension: 'js',
            meta: {
              './*.js': {
                loader: 'systemjs-angular-loader.js'
              }
            }
          },
          rxjs: {
            defaultExtension: 'js'
          }
        }
      });
    })(this);

代码工作正常,直到我安装HttpClientMoules


    import { NgModule }      from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';

    import { HttpClientModule } from '@angular/common/http';
    import { AppComponent }  from './app.component';


    @NgModule({
      imports: [
        BrowserModule,
        HttpClientModule],
      declarations: [ AppComponent ],
      bootstrap:    [ AppComponent ]
    })
    export class AppModule { }

添加HttpClientModule后,我得到一个错误:

我已经研究了很长一段时间,看了很多这样的问题,但是找不到我问题的答案。

共有2个答案

越飞语
2023-03-14

您应该添加map在System js配置@角/通用/超文本传输协议

'@angular/common/http': 'node_modules/@angular/common/bundles/common-http.umd.js'

另外它需要tslb

'tslib': 'npm:tslib/tslib.js'
巫马俊力
2023-03-14

我怀疑您应该向systemjs配置中添加以下键:

 map: {
  ...
  '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
  'tslib': 'npm:tslib/tslib.js'

普朗克例子

tslib是必需的,因为@angular/common/http依赖于它。https://github.com/angular/common-builds/blob/4.3.0/bundles/common-http.umd.js#L7

 类似资料:
  • 我得到下面的错误。我最近将更新为其最新版本,之后出现此错误。我不确定到底出了什么问题,我在谷歌上非常努力地寻找答案,因为我是一个新的角度类型的编程。 我尝试了以下步骤: 已尝试弃用返回,但运气不佳 尝试导入软件包,仍然没有成功 已尝试启动rc1,但运气不佳 你能告诉我实际的问题是什么,我应该如何解决这个问题? localhost/: 38错误:(SystemJS)XHR错误(404未找到)加载ht

  • 你好,作为角2学习项目的一部分,我正在创建一个测试应用程序。 我试图急切地加载一个名为的模块,但是,出现以下错误: 错误:(SystemJS)XHR错误(404未找到)加载http://localhost:3000/app/core.js错误:XHR错误(未找到404)加载http://localhost:3000/app/core.js在XMLHttpRequest。wrapFn[as _onr

  • 我使用角cli为我的Angular2应用程序。每当我尝试加载angular2/超文本传输协议在我的组件/服务没有错误显示在cli终端,但在我的浏览器的控制台它显示这- 收到http://localhost:4200/angular2/http404(未找到) 未处理的promise拒绝:错误:XHR错误(未找到404)加载http://localhost:4200/angular2/http在XM

  • system.config.js: 当我在“app.module.ts”的imports列表中添加时,就会出现错误。

  • 问题内容: 我试图将自定义错误消息返回给用户,以让他们知道发生错误时出了什么问题,但是我已经尝试了所有方法来显示该消息,并且似乎什么也没有捕捉到。这是我的角度代码: 这是它正在调用的 styleAPIservice 函数: 这是 API 函数: 这是发生错误时返回的内容(例如Style已经存在): 我究竟做错了什么?我觉得自己到处都在搜索,并尝试了所有可能的建议,但是对于为什么我无法显示错误消息我

  • 我试图调用一个示例API(https://jsonplaceholder.typicode.com/posts)通过使用接口在角度上。 然而,我得到以下错误。错误HttpErrorResponse 下面是我的TS文件的代码