in my project I was using Angular 9 and adequate version of ngx-monaco-editor (9.0.0). After update them both to version 12, I can't use monaco namespace anymore.

Problem looks like similar to this: https://github.com/microsoft/monaco-editor/issues/757
I thought that it may be something wrong with my app so I decided to reproduce this issue on new project but got the same results:

I followed this guide: https://github.com/atularen/ngx-monaco-editor#readme during creating a new project
package.json in new project:
 {
   "name": "my-app",
   "version": "0.0.0",
   "scripts": {
      "ng": "ng",
      "start": "ng serve",
      "build": "ng build",
      "watch": "ng build --watch --configuration development",
      "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~12.2.0",
    "@angular/common": "~12.2.0",
    "@angular/compiler": "~12.2.0",
    "@angular/core": "~12.2.0",
    "@angular/forms": "~12.2.0",
    "@angular/platform-browser": "~12.2.0",
    "@angular/platform-browser-dynamic": "~12.2.0",
    "@angular/router": "~12.2.0",
    "monaco-editor": "^0.24.0",
    "ngx-monaco-editor": "^12.0.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.2.1",
    "@angular/cli": "~12.2.1",
    "@angular/compiler-cli": "~12.2.0",
    "@types/jasmine": "~3.8.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.8.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.3.5"
  }
}
                UPD2: Real solution was to add triple-slash reference directive to every file which accesses monaco:
/// <reference path="../../../../../node_modules/monaco-editor/monaco.d.ts" />
Information below does not represent a working solution:
I've solved the problem by adding new value to compilerOptions.types array in my tsconfig.lib.json:
"types": ["../../node_modules/monaco-editor/monaco"],
Alternative way is to just add import to every file:
import * as monaco from 'monaco-editor'
UPD: This solution does not work as it links monaco-editor css files which fails the bundler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With