Angular2 System.js找不到jspm包

时间:2015-12-13 19:35:25

标签: javascript angular jspm

我正在尝试编写一个简单的Angular2(使用Alpha 47)应用程序,我正在尝试从jspm安装“npm guid”。它安装得很好但是当我尝试运行应用程序时,我总是得到“GET http://localhost:3001/jspm_packages/npm/guid@0.0.12 404(Not Found)”。我也尝试加载其他软件包,他们也提出了404.否则我的angular2应用程序工作正常。我不确定我做错了什么。任何帮助将非常感激!谢谢!

System.js配置文件

System.config({
  baseURL: "/",
  transpiler: "none",
  paths: {
    "npm:*": "jspm_packages/npm/*",
    "github:*": "jspm_packages/github/*"
  },

  packages: {
    "app": {
      "defaultExtension": "js"
    }
  },

  map: {
    "guid": "npm:guid@0.0.12"
  }
});

的index.html

<html>
<head>
    <title>Office Contacts</title>
    <link rel="stylesheet" href="app/styles/foundation.css">
    <script src="jspm_packages/system.src.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
    <script src="node_modules/angular2/bundles/router.dev.js"></script>
    <script src="node_modules/angular2/bundles/http.dev.js"></script>
    <script src="config.js"></script>
    <base href="/">
    <script>
        System.import('app/release/bootstrap');
    </script>

    <script src="node_modules/es6-shim/es6-shim.js"></script>
</head>
<body>
<app>Loading...</app>
</body>
</html>

我的bootstrap.ts文件

//
// ANGULAR PROVIDERS
//
import {bootstrap, provide, FORM_PROVIDERS} from 'angular2/angular2';
import {ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import {ContactsService} from './contacts.service';
import {guid} from 'guid';

//
// APP COMPONENT
// Top level component that holds all of our components
//
import {App} from './app';


//
// BOOTSTRAP
// Bootstrap our app with the top level component and
// inject services and providers
//
bootstrap(App, [
    FORM_PROVIDERS,
    ROUTER_PROVIDERS,
    HTTP_PROVIDERS,
    ContactsService,
    guid,
    provide(LocationStrategy, {useClass: HashLocationStrategy})
]);

2 个答案:

答案 0 :(得分:0)

您使用的是Alpha 53吗?如果是这样: 他们摆脱了角度2 /角度2&#39;。您现在必须使用&#39; angular2 / bootstrap&#39;,&#39; angular2 / core&#39;进行导入。

我实际上有一个潜在的类似问题,其中&#39; angular2 / bootstrap&#39;没有正确导入SystemJS。

https://github.com/angular/angular/blob/master/CHANGELOG.md

答案 1 :(得分:0)

我发现您只为$.ajax({ type: 'GET', url: '/rest/api/summaryWithPicture/001', crossDomain: true, dataType: 'json', success: function(result) { var dataURI = result.picture.pictureThumbnail; $(".profileImage").attr("src", "data:image/jpeg;base64," + dataURI); } });

添加了"defaultExtension": "js"

扩展程序有问题,您是否尝试将链接复制到浏览器app,然后添加http://localhost:3001/jspm_packages/npm/guid@0.0.12以查看其是否已加载。

试试这个

.js