Skip to content

Commit

Permalink
Work around dynamic JSON import bug in webpack
Browse files Browse the repository at this point in the history
Destructuring dynamic JSON imports has been broken since webpack 5.80.0.
See webpack/webpack#17042 . Work around the
bug by avoiding the destructing pattern.
  • Loading branch information
mdmower committed May 29, 2023
1 parent 9b19917 commit cf7b10f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pages/citation.ts
Expand Up @@ -122,9 +122,15 @@ class DoiCitation {
* Import CSL styles and locales
*/
private async importCslData(): Promise<void> {
const {default: cslStyles} = await import('../csl/styles/styles.json');
// TODO: Revert this workaround once https://github.com/webpack/webpack/issues/17042 is resolved.
// webpack 5.80.0 introduced a bug where dynamically imported JSON doesn't destructure correctly.
// The issue still exists as of webpack 5.84.1.

// const {default: cslStyles} = await import('../csl/styles/styles.json');
const cslStyles = (await import('../csl/styles/styles.json')).default;
this.cslStyles_ = cslStyles;
const {default: cslLocales} = await import('../csl/locales/locales.json');
// const {default: cslLocales} = await import('../csl/locales/locales.json');
const cslLocales = (await import('../csl/locales/locales.json')).default;
this.cslLocales_ = cslLocales;
}

Expand Down

0 comments on commit cf7b10f

Please sign in to comment.