Angular gives @angular/core 404 not found error when using directives

梦想的初衷 提交于 2019-11-29 10:43:34

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';

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.

AutoMEta

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!