monaco-editor version: 0.21.0+
Browser: N/A
OS: N/A
Severity: Very high (code cannot be tested)
0.21.0 release changed var global = self; to const global = self; in node_modules/monaco-editor/esm/vs/editor/editor.api.js. Now, this constant clashes with jest's 'global' producing the following error:
SyntaxError: Identifier 'global' has already been declared
Changing the const back to var resolves the issue. The alternative solution is to rename global to anything else. Can this be fixed in 0.21.3?
git clone https://github.com/A-Shleifman/monaco-jest-global-already-declared.git
cd monaco-jest-global-already-declared
npm i
npm t
The stack-overflow issue raised a few months ago: https://stackoverflow.com/questions/64042617/identifier-global-has-already-been-declared-at-compilefunction-error-in-jest
Same issue here. Is there a solution? I can't run jest on react components that are using monaco-editor.
@emilioSp I had to use patch-package to fix the problem directly in node_modules on postinstall.
diff --git a/node_modules/monaco-editor/esm/vs/editor/editor.api.js b/node_modules/monaco-editor/esm/vs/editor/editor.api.js
index 225acdb..8e9060e 100644
--- a/node_modules/monaco-editor/esm/vs/editor/editor.api.js
+++ b/node_modules/monaco-editor/esm/vs/editor/editor.api.js
@@ -6,7 +6,7 @@ import { EditorOptions } from './common/config/editorOptions.js';
import { createMonacoBaseAPI } from './common/standalone/standaloneBase.js';
import { createMonacoEditorAPI } from './standalone/browser/standaloneEditor.js';
import { createMonacoLanguagesAPI } from './standalone/browser/standaloneLanguages.js';
-const global = self;
+var global = self;
// Set defaults for standalone editor
EditorOptions.wrappingIndent.defaultValue = 0 /* None */;
EditorOptions.glyphMargin.defaultValue = false;
"scripts": {
"postinstall": "patch-package"
}
@alexdima thanks for the fix. Any chance this will land in an upcoming release of monaco-editor ?
Most helpful comment
Fixed via https://github.com/microsoft/vscode/pull/109833