New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unintended duplicate imports can cause rendering error in standalone component life cycle. #46109
Comments
|
Would you mind sharing a minimal reproduce scenario? I think that something else is going on as I did use a standalone components with the exact list of imports you've mentioned. So I'm suspecting that ngx-bootstrap modal is a root cause / contributing factor here. In any case we really do nee a minimal reproduce scenario. |
|
@leo6104 I was trying to reproduce the issue, in both the regular usage in a template and dynamic instantiation scenarios. Here are my attempts: https://stackblitz.com/edit/angular-standalone-4r1ubq?file=src%2Fmain.ts,package.json I wasn't able to see the error given the above setup. Given this and the fact that I haven't heard back from you with the exact reproduce scenario - we can't progress on this issue. Can you extract a minimal reproduce scenario to a stackblitz and share it here? If not we will have no choice but to close this issue. |
|
@pkozlowski-opensource Sorry for late comment. I was busy on working day. I guess we load standalone component dynamically I'm trying to reproducing the error with dynamic import case. |
|
@leo6104 lazy-loading should not change the equation: https://stackblitz.com/edit/angular-standalone-wshpc1?file=src%2Fmain.ts,src%2Fapp%2Flazy.ts There must be something else going on but it is impossible to say what without a reproduce scenario. |
|
This could be an AOT compiler issue that doesn't reproduce in Stackblitz |
|
I cannot reproduce in any case but in my project it still exists. |
|
I think I might have encountered this issue, as well -- but only when I run unit tests. I had a component set up like so: import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import {
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { enterLeaveFade } from 'src/lib/animations/enterLeaveFade';
@Component({
selector: 'app-signup',
standalone: true,
imports: [
CommonModule,
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
MatButtonModule,
],
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss'],
animations: [enterLeaveFade],
})
export class SignupComponent implements OnInit {
//...
}And it's default test spec (I hadn't modified it yet): import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SignupComponent } from './signup.component';
describe('SignupComponent', () => {
let component: SignupComponent;
let fixture: ComponentFixture<SignupComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ SignupComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(SignupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});Running that spec yielded: However, I should add that I'm running 14.0.1 currently: |
During JIT compilation of standalone components the compiler did not deduplicate declarations in the imports array, unlike the AOT compiler. This may result in runtime errors during directive matching, when the same component is found multiple times resulting in NG0300, for example: > NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField. This commit fixes the issue by deduplicating imports in the JIT compiler. Relates to angular#46109 (comment) Closes angular#46109
|
@t-bowersox Thanks for the info, that does indeed reveal a JIT-only bug! I have a fix in #46439. |
During JIT compilation of standalone components the compiler did not deduplicate declarations in the imports array, unlike the AOT compiler. This may result in runtime errors during directive matching, when the same component is found multiple times resulting in NG0300, for example: > NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField. This commit fixes the issue by deduplicating imports in the JIT compiler. Relates to angular#46109 (comment) Closes angular#46109
During JIT compilation of standalone components the compiler did not deduplicate declarations in the imports array, unlike the AOT compiler. This may result in runtime errors during directive matching, when the same component is found multiple times resulting in NG0300, for example: > NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField. This commit fixes the issue by deduplicating imports in the JIT compiler. Relates to angular#46109 (comment) Closes angular#46109
During JIT compilation of standalone components the compiler did not deduplicate declarations in the imports array, unlike the AOT compiler. This may result in runtime errors during directive matching, when the same component is found multiple times resulting in NG0300, for example: > NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField. This commit fixes the issue by deduplicating imports in the JIT compiler. Relates to angular#46109 (comment) Closes angular#46109
…er (#46439) During JIT compilation of standalone components the compiler did not deduplicate declarations in the imports array, unlike the AOT compiler. This may result in runtime errors during directive matching, when the same component is found multiple times resulting in NG0300, for example: > NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField. This commit fixes the issue by deduplicating imports in the JIT compiler. Relates to #46109 (comment) Closes #46109 PR Close #46439


Which @angular/* package(s) are the source of the bug?
compiler-cli, compiler, core
Is this a regression?
No
Description
Developer expect that cause i use
mat-form-fieldmatInputdirective so put MatFormFieldModule, MatInputModule in standalone component imports. But, it can cause an error for now. When i remove MatFormFieldModule inStandaloneComponent.imports, it doesn't occur errors. The reason is that MatInputModule already import-export MatFormFieldModule. It seems angular life-cycle handler trigger without duplicate check. Developers cannot consider all module+component dependencies when they use 3rd party library (it can be changed in the future).It is not only NgModule-only problem in standalone component. I found it can be caused by duplicate imports of
Component/NgModuleboth case.Duplicate component imports can cause error too.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version)Anything else?
We use ngx-bootstrap modal to open these standalone component.
The text was updated successfully, but these errors were encountered: