angular - 错误 [karma-server]:UncaughtException:TypeError:无法读取未定义的属性“pkg”
问题描述
我在运行npm test
或ng test
我的角度项目时遇到错误。我尝试再次安装 node_modules 但没有成功。请帮助我了解问题所在。
ERROR [karma-server]: UncaughtException: TypeError: Cannot read property 'pkg' of undefined
at new Reporter (/Users/app/node_modules/istanbul-api/lib/reporter.js:24:43)
at Object.createReporter (/Users/app/node_modules/istanbul-api/index.js:16:16)
at createReport (/Users/app/node_modules/karma-coverage-istanbul-reporter/src/reporter.js:91:31)
at/Users/app/node_modules/karma-coverage-istanbul-reporter/src/reporter.js:217:9
at Array.forEach (<anonymous>:null:null)
at BrowserCollection.forEach (/Users/app/node_modules/karma/lib/browser_collection.js:91:26)
at CoverageIstanbulReporter.onRunComplete (/Users/app/node_modules/karma-coverage-istanbul-reporter/src/reporter.js:216:16)
at Server.<anonymous> (/Users/app/node_modules/karma/lib/events.js:40:26)
at Server.emit (node:events:406:35)
at emitRunCompleteIfAllBrowsersDone (/Users/app/node_modules/karma/lib/server.js:320:14)
at Server.<anonymous> (/Users/app/node_modules/karma/lib/server.js:356:9)
at Server.emit (node:events:394:28)
at Server.<anonymous> (/Users/app/node_modules/karma/lib/server.js:332:14)
at Server.emit (node:events:406:35)
at Browser.onComplete (/Users/app/node_modules/karma/lib/browser.js:94:20)
at Socket.<anonymous> (/Users/app/node_modules/karma/lib/browser.js:216:44)
at Socket.emit (node:events:394:28)
at /Users/app/node_modules/socket.io/dist/socket.js:435:32
at processTicksAndRejections (node:internal/process/task_queues:78:11)
我有简单的测试用例应该创建如下:
describe('TestComponent', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [
BrowserAnimationsModule
],
providers: []
}).compileComponents();
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
});
解决方案
推荐阅读
- python - TensorFlow 对象检测 api Windows 致命异常:访问冲突,步骤停留在 0
- javascript - Javascript 意外行为
- cassandra - 从不同的应用程序更新 cassandra 宽行列
- java - Quarkus:java.lang.IllegalStateException:找不到频道的订阅者
- android - 无法在 MacBook M1 芯片上构建 Kotlin Multiplatform 移动项目
- python - 在Python多线程中完成一个旧线程时如何启动新线程
- r - 如何在 R 中使用“fportfolio”找到切点?
- visual-studio-code - Visual Studio Code 中“添加行注释”和“切换行注释”之间的区别
- youtube - Youtube 视频 Playblack... 它是如何工作的?
- visual-studio-code - 远程 SSH 不适用于 Windows 2008 Server R2 中的最新 VS Code