kodie / moment-holiday

A Moment.js plugin for handling holidays. NO LONGER MAINTAINED (DEPRECATED)
MIT License
83 stars 86 forks source link

some issue using this in angular #29

Open capaneus opened 6 years ago

capaneus commented 6 years ago

hi, when I try to use is in angular, it gives me warning:

WARNING in ./node_modules/moment-holiday/build/moment-holiday-us.min.js
10:53-60 Critical dependency: require function is used in a way in which dependencies cannot be statically e
xtracted
WARNING in ./node_modules/moment-holiday/build/moment-holiday-us.min.js
6:3284-3296 Critical dependency: the request of a dependency is an expression

and when it's loaded in browser:

Uncaught TypeError: Cannot read property 'fn' of undefined

I'm new to js and typescript, so couldn't figure out a way to fix it. so if anyone could take a look would be awesome.

what I did in code is to test some functions:

import * as holidays from 'moment-holiday';

this.locales = holidays.load('united_kingdome');

Thanks!

Silthus commented 6 years ago

Did you find a solution for this? I am having the same problem.

lwensveen commented 6 years ago

See this PR:

https://github.com/kodie/moment-holiday/pull/31

You can use my fork like this:

    "moment-holiday": "https://github.com/lwensveen/moment-holiday.git#require",
MartinLoeper commented 6 years ago

Hi there, we at @nesto-software are currently open sourcing a new moment-holiday library which further improves this great approach by kodie. There is only a small number of supported countries yet. However if you want to check it out: https://github.com/nesto-software/moment-holiday/

For the frontend, there is an usage example.

madthad91 commented 6 years ago

Not super pretty, but this works in an angular cli project as such:

1) add the following to the scripts array of your angular-cli.json file:

    "./node_modules/moment/min/moment.min.js",
    "./node_modules/moment-holiday/build/moment-holiday-us.min.js"

2) In the file where you want to import moment-holiday, instead just add declare var moment: any; at the top of that file. Don't import moment or moment-holiday. Then use this library as normal: moment().holidaysBetween(<some_moment_object>)

EDIT: The reason why this is not too too bad, is that npmjs.com has runkit integration and you can test your code there: https://npm.runkit.com/moment-holiday

get it running, and just transfer the code to your main project

codeunifier commented 5 years ago

Still an issue - any update on this would be much appreciated.