How to use Luxon with Angular2?
Asked Answered
P

1

13

I was looking for a library to use with Angular2 to handle dates and make diff/add, translations, etc ... I tried to install Luxon (http://moment.github.io/luxon/) by installing it via npm install --save-dev @types/luxon but it fails.

I always have errors like below when I compile my code:

Module not found: Error: Can't resolve 'luxon' in 'D:\App\src\app\planning-team' resolve 'luxon' in 'D:\App\src\app\planning-team' Parsed request is a module using description file: D:\App\package.json (relative path: ./src/app/planning-team) Field 'browser' doesn't contain a valid alias configuration

Does anyone already use Luxon with Angular ? How do you do ?

Thanks for your help. Regards, Mike

Pigling answered 28/12, 2017 at 19:20 Comment(2)
You've only installed the TypeScript typings. But not the library itself: npm install --save luxon. moment.github.io/luxon/docs/manual/install.htmlShenika
Thanks @JBNizet it's working fine now using import { DateTime} from 'luxon';Pigling
P
33

This worked for me:

npm i luxon

npm i @types/luxon -D

Then your import:

import { DateTime } from 'luxon';

Now you can call const now = DateTime.local() in your Typescript.

Pliske answered 20/7, 2018 at 17:40 Comment(1)
and what happens if I don't want to include luxon in my main bundle instead of loading it from a CDN?Amperage

© 2022 - 2024 — McMap. All rights reserved.