【问题标题】:angular 2 typescript moment install not workingangular 2 typescript moment 安装不工作
【发布时间】:2016-12-30 10:47:58
【问题描述】:

我正在尝试安装时刻。

npm install moment --save之后,我在我的组件中导入了moment,但是当我重新加载页面时,我得到了404错误:http://localhost:3000/moment

这是我的组件文件导入代码:

import {Input, Output, Component} from "angular2/core"
import {TicketService} from "../services/ticket.service"
import {Ticket} from "./ticket";
import {OnInit} from "angular2/core";
import {Router, RouteParams, RouterLink, ROUTER_DIRECTIVES} from "angular2/router";
import * as moment from 'moment';

我不明白为什么。有人可以帮我吗?

这是我的 System.config

<script>
    System.config({
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
    System.import('app/boot')
            .then(null, console.error.bind(console));
</script>

【问题讨论】:

  • 尝试安装angular2-moment包。
  • 您是否定义了要在 node_modules 下映射的“地图”?
  • @echonax 不,我没有
  • 你能分享你的 system.config.js 吗?
  • @echonax 嗨,我加了,谢谢~

标签: angular momentjs systemjs npm-install


【解决方案1】:

您应该将该“时刻”路径映射到系统配置下的某些内容。所以它会知道去哪里。

 System.config({
        map:{
           'moment':                  './node_modules/moment/moment'
        },
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });

当然,具体路径可能会因您的架构而异。

【讨论】:

  • 那么就无法获取 /node_modules/moment/moment
  • 检查它是否已添加到依赖项中
  • 我只是写了路径作为例子。我不知道你的时刻主文件在哪里。你必须相应地改变它
猜你喜欢
  • 2021-05-28
  • 2017-10-16
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 2020-09-01
  • 2016-10-15
  • 2018-12-02
  • 2017-07-12
相关资源
最近更新 更多