kodie / moment-holiday

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

NodeJs: Regions is not defined (in strict_mode) #18

Open MartinLoeper opened 6 years ago

MartinLoeper commented 6 years ago

Hi, I'm getting the following error:

ReferenceError: regions is not defined
    at d (/var/app/current/node_modules/moment-holiday/build/moment-holiday-us.min.js:6:3117)
    at Object.add (/var/app/current/node_modules/moment-holiday/build/moment-holiday-us.min.js:6:5870)
    at Object.<anonymous> (/var/app/current/node_modules/moment-holiday/build/moment-holiday-us.min.js:16:116)
    at Object.<anonymous> (/var/app/current/node_modules/moment-holiday/build/moment-holiday-us.min.js:16:138)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/var/app/current/bin/src/app/utils/cost/strategies/publicHoliday.strategy.js:5:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

Any idea why this is happening?
I'm using NodeJs v8.4.0 on AWS with typescript compiler.

The library is included as follows:

import * as moment from "moment";
import "moment-holiday";
MartinLoeper commented 6 years ago

I found out, that strict_mode causes this error.
This script seems not to work on NodeJs in strict_mode.

MartinLoeper commented 6 years ago

There are several variable declarations missing.
If someone is interested in how to get this library working in strict mode, please check out my fork: https://github.com/MartinLoeper/moment-holiday

bjhewitt commented 6 years ago

@MartinLoeper are you planning to do a pull request to get your changes into this upstream repo (and thus, hopefully, into the NPM module)? I'd love to get these strict/minification issues resolved in the module to get my build working with less fuss.

For me, I had to move that variable declaration out to the top module scope to avoid minification errors. (https://github.com/bjhewitt/moment-holiday/commit/388ec0a573cdab20431868cb0892df70c5e287ca#diff-5ecd2a99d029816f5c37fce3481f99bd)

MartinLoeper commented 6 years ago

I provided the PR =)
However, I did not notice any minification errors. Everything worked well for the following command: node_modules/.bin/gulp --name=moment-holiday-de.js --locale=Germany --locale=Easter --set=Germany --set=Easter

bjhewitt commented 6 years ago

Thanks. I'm bundling and minifying numerous components together, so although moment-holiday is generating the error, it's possible there's something else at play. In any case, moving the variable declaration worked.