找不到ng2-scrollreveal 404

时间:2016-11-14 19:09:24

标签: angular scrollreveal.js

在我的Angular2应用中尝试使用ng2-scrollreveal npm,在按照所有说明操作后出现控制台错误:

zone.js:1274 GET http://localhost:3000/ng2-scrollreveal 404 (Not Found)

(index):18 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/ng2-scrollreveal(…)

的index.html

<html>
<head>
<base href="/">
<title>App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="app/assets/css/styles.css">
<link rel="stylesheet" href="app/assets/css/bootstrap-grid.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css" />

<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<script src="systemjs.config.js"></script>
<script>
  System.import('app').catch(function(err){ console.error(err); });
</script>
<script src="app/script/script.js"></script>
</head>

<my-app>
  <div class="preloader">

  </div>
</my-app>  

的package.json

{
 "name": "app",
 "version": "1.0.0",
 "scripts": {
   "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
   "lite": "lite-server",
   "postinstall": "typings install",
   "tsc": "tsc",
   "tsc:w": "tsc -w",
   "typings": "typings"
 },
 "license": "ISC",
 "dependencies": {
   "@angular/common": "2.0.0",
   "@angular/compiler": "2.0.0",
   "@angular/core": "2.0.0",
   "@angular/forms": "2.0.0",
   "@angular/http": "2.0.0",
   "@angular/platform-browser": "2.0.0",
   "@angular/platform-browser-dynamic": "2.0.0",
   "@angular/router": "3.0.0",
   "@angular/upgrade": "2.0.0",
   "angular2-in-memory-web-api": "0.0.20",
   "bootstrap": "^3.3.6",
   "core-js": "^2.4.1",
   "reflect-metadata": "^0.1.3",
   "rxjs": "5.0.0-beta.12",
   "scrollreveal": "^3.3.2",
   "ng2-scrollreveal": "^1.0.0",
   "systemjs": "0.19.27",
   "zone.js": "^0.6.23"
 },
  "devDependencies": {
   "browser-sync": "^2.16.0",
   "concurrently": "^2.2.0",
   "lite-server": "^2.2.2",
   "typescript": "^2.0.2",
   "typings": "^1.3.2"
 }
}

system.config.js

(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',
      // 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);

app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgsRevealModule } from 'ng2-scrollreveal';
import { AppComponent }   from './app.component';

import { AppRoutingModule, routingComponents }  from './app.routing';

@NgModule({
  imports:      [ NgsRevealModule.forRoot(), BrowserModule, AppRoutingModule ],
  declarations: [ AppComponent, routingComponents ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

发现与其他模块类似的问题,但建议的解决方案对我不起作用。 做错了什么?

1 个答案:

答案 0 :(得分:0)

问题是我的 system.config.js 文件未在地图方法中添加 ng2-scrollreveal

'ng2-scrollreveal': 'npm:ng2-scrollreveal/bundles/ng2-scrollreveal.min.js'

对我有用的变体如下所示:

<强> system.config.js

(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',
      // other libraries
      'ng2-scrollreveal': 'npm:ng2-scrollreveal/bundles/ng2-scrollreveal.min.js',
      '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);