首页 > 解决方案 > 错误 [karma-server]:UncaughtException:TypeError:无法读取未定义的属性“pkg”

问题描述

我在运行npm testng 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();
    });
});

标签: angularunit-testingkarma-jasmine

解决方案


推荐阅读