Angular gives @angular/core 404 not found error wh

2019-01-26 13:09发布

When I add in this line of code into my @Component:

directives: [HeroDetailComponent]

The code breaks, and gives me this error:

GET http://localhost:3000/@angular/core 404 (Not Found)

These are the scripts in my index.html:

<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>   

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

If I'm missing out any information for diagnosing this issue, please tell me and I'll include it here.

3条回答
贼婆χ
2楼-- · 2019-01-26 13:37

I had the same error when I tried to follow the Angular 2 tutorial at https://angular.io/docs/ts/latest/tutorial/toh-pt3.html.

But I find out the problem is that I had a typo in app.component.ts, the first line should be:

import { Component } from '@angular/core';

But I wrote a capital letter of 'core':

import { Component } from '@angular/Core'

So my advice is to make sure you write the right name of the resource before try to revise SystemJS.

查看更多
smile是对你的礼貌
3楼-- · 2019-01-26 13:39

If you want to use the RC version of Angular2, you need to configure SystemJS this way:

var packages = {
  'app': { main: 'main.js',  defaultExtension: 'js' },
  'rxjs': { defaultExtension: 'js' },
  'angular2-in-memory-web-api': { defaultExtension: 'js' },
};

var packageNames = [
  '@angular/common',
  '@angular/compiler',
  '@angular/core', // <--------
  '@angular/http',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',
  '@angular/router',
  '@angular/router-deprecated',
  '@angular/testing',
  '@angular/upgrade',
];

packageNames.forEach(function(pkgName) {
  packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});

var config = {
  map: map,
  packages: packages
}

System.config(config);

If you want to use beta versions, after having included the node_modules/angular2/bundles/angular2.dev.js file in a script element, import this package instead:

import {Component, Directive, ...} from 'angular2/core';
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-26 13:46

change this

import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api'; 

to ->>

import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api/in-memory-backend.service';

in your main.ts

查看更多
登录 后发表回答