admin管理员组

文章数量:1291426

I have followed the instructions at angular material2 Getting Started to install @angular/material. Via Atom, I updated package.json, app.module, and beyond the Getting Started instructions, I updated systemjs.config, as follows: '@angular/material':'node_modules/@angular/material',

I get these errors: zone.js:1274 GET http://localhost:3000/node_modules/@angular/material/ 404 (Not Found)

(SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular/material(…)

I believe I have tracked the problem to the fact that many @angular folders have a bundle sub-folder containing the umd file, but the @angular/material folder does not have a bundle sub-folder. Hence, the 'unpacking' function can't find @angular/material/material.umd.js

systemjs is outside my fort zone so I'm not sure of the above, but I am not able to solve the 404 problem with the new file structure of alpha.9-3 Here is relevant code (other ponents are not shown).

package.json

 "@angular/material": "2.0.0-alpha.9-3",

app.module

 import { MaterialModule } from '@angular/material';
 @NgModule({
  imports: MaterialModule.forRoot(),

systemjs.config

  (function(global) {
    var map = {
      'app': 'app',
      // angular bundles
      '@angular':                   'node_modules/@angular',
      // other libraries
      'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
      'rxjs':                       'node_modules/rxjs',
      '@angular/material': 'node_modules/@angular/material',
    };
    var packages = {
      'app': { main: 'main.js',  defaultExtension: 'js' },
      'rxjs':{ defaultExtension: 'js' },
      'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
    };
    var ngPackageNames = [
     'mon',
     'piler',
     'core',
     'forms',
     'http',
     'platform-browser',
     'platform-browser-dynamic',
     'platform-server',
     'router',
     'upgrade',
    ]; //adding 'material' to the array causes a different 404 error
    function packIndex(pkgName) {
      packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    function packUmd(pkgName) {
      packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    ngPackageNames.forEach(setPackageConfig); 
    var config = {
      map: map,
      packages: packages
    };
    System.config(config);

  })(this); //end of function(global)

I have checked my folder/file structure and @angular/material/material.umd.js is definitely there. How do I get rid of the 404 not found?

I have followed the instructions at angular material2 Getting Started to install @angular/material. Via Atom, I updated package.json, app.module, and beyond the Getting Started instructions, I updated systemjs.config, as follows: '@angular/material':'node_modules/@angular/material',

I get these errors: zone.js:1274 GET http://localhost:3000/node_modules/@angular/material/ 404 (Not Found)

(SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular/material(…)

I believe I have tracked the problem to the fact that many @angular folders have a bundle sub-folder containing the umd file, but the @angular/material folder does not have a bundle sub-folder. Hence, the 'unpacking' function can't find @angular/material/material.umd.js

systemjs is outside my fort zone so I'm not sure of the above, but I am not able to solve the 404 problem with the new file structure of alpha.9-3 Here is relevant code (other ponents are not shown).

package.json

 "@angular/material": "2.0.0-alpha.9-3",

app.module

 import { MaterialModule } from '@angular/material';
 @NgModule({
  imports: MaterialModule.forRoot(),

systemjs.config

  (function(global) {
    var map = {
      'app': 'app',
      // angular bundles
      '@angular':                   'node_modules/@angular',
      // other libraries
      'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
      'rxjs':                       'node_modules/rxjs',
      '@angular/material': 'node_modules/@angular/material',
    };
    var packages = {
      'app': { main: 'main.js',  defaultExtension: 'js' },
      'rxjs':{ defaultExtension: 'js' },
      'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
    };
    var ngPackageNames = [
     'mon',
     'piler',
     'core',
     'forms',
     'http',
     'platform-browser',
     'platform-browser-dynamic',
     'platform-server',
     'router',
     'upgrade',
    ]; //adding 'material' to the array causes a different 404 error
    function packIndex(pkgName) {
      packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    function packUmd(pkgName) {
      packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    ngPackageNames.forEach(setPackageConfig); 
    var config = {
      map: map,
      packages: packages
    };
    System.config(config);

  })(this); //end of function(global)

I have checked my folder/file structure and @angular/material/material.umd.js is definitely there. How do I get rid of the 404 not found?

Share edited Jan 6, 2017 at 18:03 Splaktar 5,9045 gold badges45 silver badges75 bronze badges asked Oct 10, 2016 at 19:37 Mike_LairdMike_Laird 1,1244 gold badges17 silver badges41 bronze badges 1
  • The angular-material tag should be removed since this doesn't relate to that library for Angular 1.x. – Splaktar Commented Jan 5, 2017 at 20:40
Add a ment  | 

1 Answer 1

Reset to default 10

Remove the following from map

'@angular/material': 'node_modules/@angular/material',

Add material to ngPackageNames array:

var ngPackageNames = [
 ...
 'material'
];

And then replace your packUmd function with

function packUmd(pkgName) {
   packages['@angular/'+pkgName] = { 
     main: (pkgName !== 'material' ? 'bundles/' : '') + pkgName + '.umd.js', 
     defaultExtension: 'js' 
   };
}

After that it should work

Or use this config like in angular2 quick start:

(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/mon': 'npm:@angular/mon/bundles/mon.umd.js',
      '@angular/piler': 'npm:@angular/piler/bundles/piler.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/animations': 'npm:@angular/animations/bundles/animations.umd.js',
      '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
      '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
      '@angular/material': 'npm:@angular/material/bundles/material.umd.js'

      // other libraries
      'rxjs':                       'npm:rxjs'
    },
    // 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'
      }
    }
  });
})(this);

本文标签: javascriptAngular2 Material Design alpha93 has 39404 not found39 for angularmaterialStack Overflow