Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度2+;角度内存web api区域获取http://localhost:3000/traceur 404(未找到)_Javascript_Api_Angular_Typescript - Fatal编程技术网

Javascript 角度2+;角度内存web api区域获取http://localhost:3000/traceur 404(未找到)

Javascript 角度2+;角度内存web api区域获取http://localhost:3000/traceur 404(未找到),javascript,api,angular,typescript,Javascript,Api,Angular,Typescript,嗨,我有一个关于内存中的web api的问题。我尝试在SystemJS和其他解决方案中使用angular2内存web api,但没有结果。我正在使用官方的快速入门模板。 谢谢你的帮助 错误列表 zone.js:1382 GET http://localhost:3000/traceur 404 (Not Found) dashboard:19 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/tr

嗨,我有一个关于内存中的web api的问题。我尝试在SystemJS和其他解决方案中使用angular2内存web api,但没有结果。我正在使用官方的快速入门模板。 谢谢你的帮助

错误列表

zone.js:1382 GET http://localhost:3000/traceur 404 (Not Found)
dashboard:19 Error: (SystemJS) XHR error (404 Not Found) loading 
http://localhost:3000/traceur
    Error: XHR error (404 Not Found) loading http://localhost:3000/traceur
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:698:29)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:265:35)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:154:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:335:33)
    Error loading http://localhost:3000/traceur
    Unable to load transpiler to transpile http://localhost:3000/node_modules/angular-in-memory-web-api/in-memory-web-api.module.js
    Error loading http://localhost:3000/node_modules/angular-in-memory-web-api/in-memory-web-api.module.js as "angular-in-memory-web-api/in-memory-web-api.module" from http://localhost:3000/app/app.module.js
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:698:29)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:265:35)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:154:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:335:33)
    Error loading http://localhost:3000/traceur
    Unable to load transpiler to transpile http://localhost:3000/node_modules/angular-in-memory-web-api/in-memory-web-api.module.js
    Error loading http://localhost:3000/node_modules/angular-in-memory-web-api/in-memory-web-api.module.js as "angular-in-memory-web-api/in-memory-web-api.module" from http://localhost:3000/app/app.module.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',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.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: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);
Package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "docker-build": "docker build -t ng2-quickstart .",
    "docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
    "pree2e": "npm run webdriver:update",
    "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "postinstall": "typings install",
    "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
    "test-once": "tsc && karma start karma.conf.js --single-run",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "webdriver:update": "webdriver-manager update"
  },
  "keywords": [],
  "author": "",
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/angular/angular.io/blob/master/LICENSE"
    }
  ],
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@angular/upgrade": "~2.1.0",

    "angular2-in-memory-web-api": "~0.1.5",
    "bootstrap": "^3.3.7",
    "systemjs": "0.19.39",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3",
    "typings": "^1.4.0",

    "canonical-path": "0.0.2",
    "http-server": "^0.9.0",
    "tslint": "^3.15.1",
    "lodash": "^4.16.2",
    "jasmine-core": "~2.5.2",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-htmlfile-reporter": "^0.3.4",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^3.3.0",
    "rimraf": "^2.5.4"
  },
  "repository": {}
}
应用程序模块

import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import {HttpModule} from "@angular/http";
import { AppRoutingModule }     from './app-routing.module';
import { InMemoryWebApiModule } from 'angular-in-memory-web-api/in-memory-web-api.module';
import { InMemoryDataService }  from './in-memory-data.service';


import { AppComponent }         from './app.component';
import { DashboardComponent }   from './dashboard.component';
import { HeroDetailComponent }  from './hero-detail.component';
import { HeroesComponent }      from './heroes.component';
import { HeroService }          from './hero.service';




@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    InMemoryWebApiModule.forRoot(InMemoryDataService),
    AppRoutingModule
  ],
  declarations: [
    AppComponent,
    DashboardComponent,
    HeroDetailComponent,
    HeroesComponent
  ],
  providers: [ HeroService ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

angular2内存web api
的0.1.13版有一些突破性的更改,教程似乎还没有更新

根据变更日志:

在systemjs.config.js中,应将映射更改为:

'angular-in-memory-web-api':'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'

然后从包中删除:

'angular-in-memory-web-api':{
main:'./index.js',
defaultExtension:'js'
}

链接到chang

还提出了一个问题

它表示通过更改来更新
app.module.ts

import{inMemoryWebAPI.module}来自“角度内存web api/内存web api.module”


从“角度内存web api”导入{inMemoryWebAPI模块}

出于某种原因,即使在关注@joel的答案和github上的问题之后,我仍然会收到相同的错误

如果任何人面临相同的问题,请遵循以下步骤:

将下面的行添加到systemjs.config.js文件中的“map”对象中

'angular-in-memory-web-api': 'node_modules/angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
本质上,这里您指向的是存在于node_modules文件夹中的umd.js文件

systemjs.config.js文件的packages对象中,添加以下行

'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
这些更改仅适用于大于0.1.13的版本,因此请在您的包中验证.json是否“angular in memory web api”的版本大于或等于0.1.13,即

"angular-in-memory-web-api": "~0.1.13", 

希望这有帮助

对于那些遵循教程的人,在我遵循Joel的答案之后,它让我直接进入另一个问题,并给出以下错误

ctorParameters.map is not a function at ReflectionCapabilities.parameters
让我来回答这个问题:


我不得不在packages.json中将“angular in memory web api”从0.1.13更新为0.2.0,即使在我尝试了前面提到的一切之后,我仍然会遇到以下错误:

“originalStack”:“错误:(SystemJS)XHR错误(404未找到)加载节点\模块/内存中的angular web api/bundles/内存中的web api.umd.js\n\t错误:XHR错误(404未找到)加载节点\模块/内存中的angular web api/bundles/内存中的web api.umd.js\n\t在XMLHttpRequest.wrapFn处[as \ onreadystatechange](node_modules/zone.js/dist/zone.js:889:29)[]\n\t在zone.runTask(node_modules/zone.js/dist/zone.js:151:47)[=>]

然后我意识到,它只会在测试期间发生(不,如果测试失败,我不会尝试启动服务器)

这对我很有用:

  • systemjs.config.js由其他人在这里描述(同时在原始示例代码中修复):
    'angular-in-memory-web-api':'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',

  • karma.conf.js:
    
    档案:[
    (...)
    'node_modules/angular内存中web api/bundles/in-memory web api.umd.js',
    (...)
    {pattern:'node_modules/angular in memory web api/***.js',include:false,wasted:false},
    ]

另外,我必须为
{provide:APP\u BASE\u HREF,useValue:“/”}
设置一个提供者,因为karma不使用index.html

最后,所有测试都通过了,我可以做我的“npm开始”:-)