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

Build fails due to missing data #27

Closed
galabra opened this issue Apr 28, 2020 · 2 comments
Closed

Build fails due to missing data #27

galabra opened this issue Apr 28, 2020 · 2 comments

Comments

@galabra
Copy link

galabra commented Apr 28, 2020

I've added the following object to the plugins array in webpack.config:

// `currentYear` is obviously defined above:
// const currentYear = new Date().getFullYear();
new MomentTimezoneDataPlugin({
    startYear: currentYear - 1,
    endYear: currentYear + 1,
    matchCountries: ['US', 'CA'],
}),

When I try to start my project, I get the following error stack:

TypeError: Cannot read property 'length' of undefined
    at findStartAndEndIndex (.../node_modules/moment-timezone/moment-timezone-utils.js:249:18)
    at filterYears (.../node_modules/moment-timezone/moment-timezone-utils.js:282:16)
    at Function.filterLinkPack (.../node_modules/moment-timezone/moment-timezone-utils.js:308:21)
    at filterData (.../node_modules/moment-timezone-data-webpack-plugin/src/index.js:100:34)
    at .../node_modules/moment-timezone-data-webpack-plugin/src/index.js:190:34
    at .../node_modules/webpack/lib/NormalModuleReplacementPlugin.js:36:8
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (.../node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:19:16)
    at .../node_modules/webpack/lib/NormalModuleFactory.js:138:29
    at .../node_modules/webpack/lib/NormalModuleFactory.js:346:9

The faulty line is endI = untils.length + 1, so I tried printing the faulty source that's missing untils and apparently it's this one, which contains only the name key:

 { name: 'America/Indiana/Indianapolis' }

Couldn't find any previous occurrence to this error, so I hope you can help.
Thanks a lot!

@gilmoreorless
Copy link
Owner

Ooh yep, looks like a bug in this plugin, passing the wrong data into moment-timezone. When I try your configuration I get the same failure, but if I try using matchZones: 'America/Indiana/Indianapolis' instead of matchCountries, it works fine.

I'll take a look and get a fix ready.

@gilmoreorless
Copy link
Owner

The bug was a hidden assumption in my code that the list of zones for each country would not contain any links to other zones, because that's how the IANA source files define them. This turned out not to be true: moment/moment-timezone#835

I've added a workaround and released version 1.3.0.

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