J.L
J.L

Reputation: 592

angular 2 typescript moment install not working

I am trying to install moment.

After npm install moment --save, I import moment in my component, but when reload the page, I got 404 error: http://localhost:3000/moment

here is my component file import code:

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

I don't understand why. Could someone help me on that ?

Here is my System.config

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

Upvotes: 3

Views: 380

Answers (1)

eko
eko

Reputation: 40657

You should map that 'moment' path to something under your system config. So it will know where to go.

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

The exact path may vary depending on your architecture of course.

Upvotes: 1

Related Questions