Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i had bug in angular2-moment #11

Closed
Ngocphu123 opened this issue Feb 1, 2016 · 15 comments
Closed

i had bug in angular2-moment #11

Ngocphu123 opened this issue Feb 1, 2016 · 15 comments

Comments

@Ngocphu123
Copy link

i used ionic 2 and angular2 for build app.

im run npm install --save angular2-moment
and i add import {TimeAgoPipe} from 'angular2-moment';
pipes: [TimeAgoPipe],
for file .js
but it error
Module parse failed: D:\xampp\htdocs\1000ngayvang_app\node_modules\angular2-mome
nt\TimeAgoPipe.ts Line 3: Unexpected token
You may need an appropriate loader to handle this file type.

@urish
Copy link
Owner

urish commented Feb 1, 2016

Can you try to change the import to

import {TimeAgoPipe} from 'angular2-moment/TimeAgoPipe.js';

and see if it helps?

@Ngocphu123
Copy link
Author

thanks you so much

2016-02-02 5:18 GMT+07:00 Uri Shaked notifications@github.com:

Can you try to change the import to

import {TimeAgoPipe} from 'angular2-moment/TimeAgoPipe.js';

and see if it helps?


Reply to this email directly or view it on GitHub
#11 (comment)
.

                         Bùi Ngọc Phú

                         Mail:strongover@gmail.com

                         Phone: 0901 443 593

@urish urish closed this as completed Feb 2, 2016
@danielgolub
Copy link

Hi,

I have the same bug. (even when I use @urish solution)

@urish
Copy link
Owner

urish commented Feb 6, 2016

@danielgolub are you using typescript?
have you got the latest release of angular2-moment (that is version 0.3.0)

@danielgolub
Copy link

@urish Yes.
I just installed it few minutes ago.

@urish
Copy link
Owner

urish commented Feb 6, 2016

Can you please include the output that you get?

@danielgolub
Copy link

When using the import code from the README file:
image

When using the solution your wrote in this chat earlier:
image

@urish
Copy link
Owner

urish commented Feb 6, 2016

seems to be a configuration problem. When you go to http://localhost:3000/angular2-moment, do you see the code of the module or a 404 error page?

@danielgolub
Copy link

404 error page.

@urish
Copy link
Owner

urish commented Feb 6, 2016

I would suggest to check your configuration, if you are using system.js you need to configure the module loader correctly so that it can correctly locate the angular2-moment package inside your node_modules directory.

@danielgolub
Copy link

Well I followed the "Hero" setup on angular.io website.
Here are the different configuration files I have:

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

package.json:

{
  "name": "SHIELDoX",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "angular2-moment": "^0.3.0",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "systemjs": "0.19.6",
    "zone.js": "0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
  }
}

And on index.html:

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

@urish
Copy link
Owner

urish commented Feb 6, 2016

Can you please upload the entire code to a git repo?

@danielgolub
Copy link

@urish, I added you as a collaborator on the git repo.

@urish
Copy link
Owner

urish commented Feb 6, 2016

Seems like the following System.js configuration should do the trick for you:

System.config({
    packageConfigPaths: ['node_modules/*/package.json'],
    paths: {
        'moment': '/node_modules/moment',
        'angular2-moment/*': '/node_modules/angular2-moment/*',
    },
    packages: {
        app: {
            format: 'register',
            defaultExtension: 'js'
        }
    },
    meta: {
        moment: {
            format: 'global',
            globals: {
                moment: 'moment'
            }
        }
    }
});

And then, import the module as follows:

import {TimeAgoPipe} from 'angular2-moment/TimeAgoPipe.js'; 

In general, I would suggest to study System.js in detail if you intend to use it in your project, it will save you much time in the future.

@danielgolub
Copy link

It works.
Anyway, I will read some more articles about System.js. It seems I was too enthusiastic about Angular2 that I ran too fast :P

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants