angular - Uncaught TypeError : ace. acequire 不是函数

我已将 ng2-ace-editor 用于其中一个组件,并尝试使用 ng test 命令运行测试用例。但由于某些原因,它抛出了 Uncaught TypeError: ace.acequire is not a function 错误。

这是我的 .spec.ts 文件代码:

import { NewModule } from './new.module';
import {AceEditorModule} from 'ng2-ace-editor';
import 'brace';
import 'brace/mode/json';
import 'brace/ext/language_tools';

describe('NewModule', () => {
  let component: NewModule;
  let fixture: ComponentFixture<Module>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [ MaterialModule, ReactiveFormsModule, FormsModule, HttpModule, 
        HttpClientTestingModule, RouterTestingModule, BrowserAnimationsModule,
        AceEditorModule
      ],
      declarations: [ NewModule ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NewModule);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

我不知道如何解决这个问题。在某个地方我知道大括号是依赖项并且需要安装它。我确实安装了支架,但它不起作用。我尝试在 angular.json 的脚本中提供依赖项文件,但它不起作用。

代码如下:

"scripts": [
   "node_modules/ace-builds/src-min/ace.js",
   "node_modules/ace-builds/src-min/ext-language_tools.js",
   "node_modules/ace-builds/src-min/mode-javascript.js",
   "node_modules/ace-builds/src-min/mode-typescript.js",
   "node_modules/ace-builds/src-min/mode-json.js",
   "node_modules/ace-builds/src-min/theme-eclipse.js"
]

因为这个其他规范文件没有运行, karma 抛出下面提到的错误。请建议我需要做什么。

Uncaught TypeError: ace.acequire is not a function
    at language_tools.js:1954
    at Object../node_modules/brace/ext/language_tools.js (language_tools.js:1955)
    at __webpack_require__ (bootstrap:76)

最佳答案

我遇到了同样的问题,并通过在 xx.component .ts 文件而不是 .spec.ts 文件中添加代码来修复它。

import 'brace';

https://stackoverflow.com/questions/56834637/

相关文章:

python - 在 zipapp 存档中嵌入 numpy

javascript - 如何在javascript中将文件移动到drive api v3中的垃圾桶

javascript - 让 WebStorm 识别 jest.setupFilesAfterEnv

javascript - 如何将组添加到 buefy b-taginput?

sql - 如何在 AWS Athena 中编写多个 SQL 语句,如 CREATE 表(使用 CL

python - 如何模拟类方法的 cls 参数?

c# - Asp.net core Identity登录成功重定向回登录页面

android-studio - 安卓工作室 : Cannot get DialogFragment

python - 如何使用 python 在我的 github 帐户上创建远程 git 存储库或使用

ruby - Jekyll:尽管安装了最新版本,但命令未发现问题