Angular 2 + angular-in-memory-web-api zone GET http://localhost:3000/traceur 404 (Not Found)

后端 未结 4 1033
野的像风
野的像风 2021-02-07 13:20

Hi I have a problem with angular-in-memory-web-api. I tried to use angular2-in-memory-web-api in SystemJS and another solutions her but with no result. I\'m using official quick

4条回答
  •  我寻月下人不归
    2021-02-07 13:57

    Even after I tried everything mentioned before I still got this error:

    "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/angular-in-memory-web-api/bundles/in-memory-web-api.umd.js\n\tError: XHR error (404 Not Found) loading node_modules/angular-in-memory-web-api/bundles/in-memory-web-api.umd.js\n\t at XMLHttpRequest.wrapFn [as _onreadystatechange] (node_modules/zone.js/dist/zone.js:889:29) []\n\t at Zone.runTask (node_modules/zone.js/dist/zone.js:151:47) [ => ]

    Then I realized, that it only occurs during tests with karma (no ... I do not try start the server if tests fail).

    This worked for me:

    • systemjs.config.js as described by others here (and meanwhile fixed in original sample code): 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',

    • karma.conf.js: files: [ (...) 'node_modules/angular-in-memory-web-api/bundles/in-memory-web-api.umd.js', (...) { pattern: 'node_modules/angular-in-memory-web-api/**/*.js', included: false, watched: false }, ]

    additional I had to set a provider for { provide: APP_BASE_HREF, useValue: "/" } because karma doesn't use the index.html

    finally all tests passed and I can do my "npm start" :-)

提交回复
热议问题