ngx-monaco-editor 中的“monaco”命名空间问题

问题描述 投票:0回答:2

在我的项目中,我使用 Angular 9 和适当版本的 ngx-monaco-editor (9.0.0)。 将它们都更新到版本 12 后,我无法再使用 monaco 命名空间了。

enter image description here

问题看起来与此类似:https://github.com/microsoft/monaco-editor/issues/757

我认为我的应用程序可能有问题,所以我决定在新项目上重现此问题,但得到了相同的结果:

enter image description here

我在创建新项目期间遵循了本指南:https://github.com/atularen/ngx-monaco-editor#readme 新项目中的

package.json

{ "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" } }
    
monaco-editor angular12
2个回答
2
投票

UPD2:真正的解决方案是向访问摩纳哥的每个文件添加三斜杠引用指令:

/// <reference path="../../../../../node_modules/monaco-editor/monaco.d.ts" />

以下信息并不代表有效的解决方案:

我已经通过向 tsconfig.lib.json 中的 compilerOptions.types 数组添加新值来

解决了问题:

"types": ["../../node_modules/monaco-editor/monaco"],
另一种方法是仅向每个文件添加导入:

import * as monaco from 'monaco-editor'

UPD:此解决方案不起作用,因为它链接了 monaco-editor css 文件,导致捆绑器失败。


0
投票
在您使用 monaco 的地方添加此行

declare const monaco: typeof import('monaco-editor');
    
© www.soinside.com 2019 - 2024. All rights reserved.