3

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>
6
  • Try to install angular2-moment package. Commented Dec 30, 2016 at 10:49
  • Did you define your 'map' to be mapped under node_modules? Commented Dec 30, 2016 at 10:50
  • @echonax no, I didn't Commented Dec 30, 2016 at 10:50
  • Can you share your system.config.js? Commented Dec 30, 2016 at 10:51
  • @echonax hi, I added, thanks~ Commented Dec 30, 2016 at 10:52

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

then it's Cannot GET /node_modules/moment/moment
checked it's added in the dependencies
I just wrote the path as an example. I don't know where your moment main file is. You must change it accordingly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.