I am getting a Field 'browser' doesn't contain a valid alias configuration
My setup is quite standard (I haven't updated much of the conifg)
There is one angular project and one angular library in a workspace
-common
--src
---lib
----components
-----input
-website
--src
---app
----sign-up
I have a mock folder inside the input component that defines the @input and @output to use in tests. The app builds fine with the common component imported in, but tests are erroring.
Mock component
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { InputConfig } from '../input.component';
@Component({
selector: 'lib-input',
templateUrl: '',
})
export class MockInputComponent {
@Input() config: InputConfig;
@Output() valueChange: EventEmitter<string | number> = new EventEmitter<string | number>();
}
Test set up
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MockInputComponent } from '@common/components/partials/input/mocks/mock-input.component';
import { SignUpComponent } from './sign-up.component';
describe('SignUpComponent', () => {
let component: SignUpComponent;
let fixture: ComponentFixture<SignUpComponent>;
beforeEach(waitForAsync( () => {
TestBed.configureTestingModule({
declarations: [SignUpComponent, MockInputComponent],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SignUpComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
My tsconfig
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@common/*": ["projects/common/src/lib/*"],
"@website/*": ["projects/website/src/*"]
},
"resolveJsonModule": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"typeRoots": ["node_modules/@types"],
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"strictNullChecks": true,
"alwaysStrict": true,
"target": "es2015",
"module": "es2020",
"lib": ["es2019", "dom"],
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"fullTemplateTypeCheck": true,
"strictInputAccessModifiers": true,
"strictInjectionParameters": true
}
}
In my library I have a common input, it all works fine in the project component, but when trying to import the mock of the component it gives that error when running tests. I assume there is some set up/config I haven't done yet, but I am scratching my head.
Full error
Error: Entry module not found: Error: Can't resolve '/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks' in '/Users/julian/other/idea-2/web'
resolve '/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks' in '/Users/julian/other/idea-2/web'
using description file: /Users/julian/other/idea-2/web/package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
root path /Users/julian/other/idea-2/web/projects/website
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.js doesn't exist
as directory
/Users/julian/other/idea-2/web/projects/website/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks doesn't exist
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/common/src/lib/components/partials/input/mocks)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks is not a file
.ts
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks.js doesn't exist
as directory
existing directory
using path: /Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/common/src/lib/components/partials/input/mocks/index)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.js doesn't exist
Error: ./projects/common/src/lib/components/partials/input/mocks/mock-input.component.ts
Module not found: Error: Can't resolve './' in '/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks'9m
resolve './' in '/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks'
Parsed request is a directory
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/common/src/lib/components/partials/input/mocks)
Field 'browser' doesn't contain a valid alias configuration
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/common/src/lib/components/partials/input/mocks)
as directory
existing directory
using path: /Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index
using description file: /Users/julian/other/idea-2/web/package.json (relative path: ./projects/common/src/lib/components/partials/input/mocks/index)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.js doesn't exist
[/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index]
[/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.ts]
[/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.tsx]
[/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.mjs]
[/Users/julian/other/idea-2/web/projects/common/src/lib/components/partials/input/mocks/index.js]
@ ./projects/common/src/lib/components/partials/input/mocks/mock-input.component.ts 2:0-50 16:18-38
@ ./projects/website/src/app/sign-up/sign-up.component.spec.ts
@ ./projects/website/src sync \.spec\.ts$
@ ./projects/website/src/test.ts