Downgrade monaco-editor-webpack-plugin to 7.1.0 to fix CDN worker loading

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 <noreply@anthropic.com>
This commit is contained in:
Matt Godbolt
2025-10-22 13:14:13 -05:00
parent 4080457f2c
commit 75ba5bc308
2 changed files with 5 additions and 5 deletions

View File

@@ -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",