From 75ba5bc308c9efb4cd055242005bad82efad6e26 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Wed, 22 Oct 2025 13:14:13 -0500 Subject: [PATCH] Downgrade monaco-editor-webpack-plugin to 7.1.0 to fix CDN worker loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Version 7.1.1 (released Oct 10, 2025) breaks Monaco editor when static assets are served from a CDN (cross-origin). Workers fail to load with "Cannot use import statement outside a module" errors. Root Cause: ----------- When workers are loaded cross-origin, the webpack plugin creates a blob worker to work around browser security restrictions. In 7.1.1, the blob generation code (lines 178-184 in webpack-plugin/src/index.ts) checks: if (typeof import.meta !== 'undefined') { js += 'import "' + workerUrl + '";'; // ES6 module syntax } else { js += 'importScripts("' + workerUrl + '");'; // Classic syntax } This check runs at BUILD TIME (in the webpack runtime context), not in the worker context. If import.meta is defined in the build environment, it generates ES6 import syntax. However, the blob is still created as a CLASSIC worker (not {type: 'module'}), causing the syntax error. Why It Works Locally: --------------------- When serving from the same origin (localhost), the plugin returns the worker URL directly without creating a blob, bypassing this buggy code. CDN deployments always trigger the cross-origin blob worker path. Symptoms: --------- - Browser console: "Could not create web worker(s). Falling back to..." - No worker.js files requested from CDN (falls back before trying) - Monaco editor loads but with degraded functionality - Console errors: "Uncaught SyntaxError: Cannot use import statement outside a module" from blob URLs The bug was introduced in commit ae5cab7 (PR #4742) which attempted to add module worker support but broke the cross-origin blob worker path. Upgrade Path: ------------- Can upgrade when either: 1. monaco-editor-webpack-plugin releases a fix (watch PR #4742 discussion) 2. We switch to same-origin worker delivery (not using CDN for workers) Pinning to exact version 7.1.0 (no caret) to prevent auto-upgrade until this is resolved upstream. Related upstream issues: - https://github.com/microsoft/monaco-editor/issues/4741 - https://github.com/microsoft/monaco-editor/pull/4742 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2a120c1c..a3e71c4ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,7 +107,7 @@ "lint-staged": "^16.2.5", "mini-css-extract-plugin": "^2.9.4", "mock-fs": "^5.5.0", - "monaco-editor-webpack-plugin": "^7.1.1", + "monaco-editor-webpack-plugin": "7.1.0", "nock": "^14.0.10", "npm-run-all": "^4.1.5", "sass": "^1.93.2", @@ -11560,9 +11560,9 @@ "license": "MIT" }, "node_modules/monaco-editor-webpack-plugin": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/monaco-editor-webpack-plugin/-/monaco-editor-webpack-plugin-7.1.1.tgz", - "integrity": "sha512-WxdbFHS3Wtz4V9hzhe/Xog5hQRSMxmDLkEEYZwqMDHgJlkZo00HVFZR0j5d0nKypjTUkkygH3dDSXERLG4757A==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/monaco-editor-webpack-plugin/-/monaco-editor-webpack-plugin-7.1.0.tgz", + "integrity": "sha512-ZjnGINHN963JQkFqjjcBtn1XBtUATDZBMgNQhDQwd78w2ukRhFXAPNgWuacaQiDZsUr4h1rWv5Mv6eriKuOSzA==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index c7efb6ac5..c934ba235 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,7 @@ "lint-staged": "^16.2.5", "mini-css-extract-plugin": "^2.9.4", "mock-fs": "^5.5.0", - "monaco-editor-webpack-plugin": "^7.1.1", + "monaco-editor-webpack-plugin": "7.1.0", "nock": "^14.0.10", "npm-run-all": "^4.1.5", "sass": "^1.93.2",