From f4c5d566a05fe84f43e7af9265f44fb7c308dc5a Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 4 Mar 2024 09:30:23 +0000 Subject: [PATCH] fix: bundling with Angular CLI and Webpack `postcss-media-query-parser` is a CommonJS (CJS) module, and its default export differs from the ECMAScript Module (ESM) format. This variance causes `critters` to encounter issues when bundled with webpack. --- packages/critters/src/css.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/critters/src/css.js b/packages/critters/src/css.js index 48cf03c..7b69d69 100644 --- a/packages/critters/src/css.js +++ b/packages/critters/src/css.js @@ -239,7 +239,9 @@ function validateMediaType(node) { * is HTML safe and does not cause any injection issue */ export function validateMediaQuery(query) { - const mediaTree = mediaParser(query); + // The below is needed for consumption with webpack. + const mediaParserFn = 'default' in mediaParser ? mediaParser.default : mediaParser; + const mediaTree = mediaParserFn(query); const nodeTypes = new Set(['media-type', 'keyword', 'media-feature']); const stack = [mediaTree];