From cf7b10fe5c8ef9df6da43ad2afcf63ece46a19df Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Mon, 29 May 2023 14:52:16 -0700 Subject: [PATCH] Work around dynamic JSON import bug in webpack Destructuring dynamic JSON imports has been broken since webpack 5.80.0. See https://github.com/webpack/webpack/issues/17042 . Work around the bug by avoiding the destructing pattern. --- src/pages/citation.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/citation.ts b/src/pages/citation.ts index f86baee..c4c8956 100644 --- a/src/pages/citation.ts +++ b/src/pages/citation.ts @@ -122,9 +122,15 @@ class DoiCitation { * Import CSL styles and locales */ private async importCslData(): Promise { - 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; }