Encountering a 'firstCreatePass' Error in Angular Library Using PrimeNg

Currently, I am in the process of integrating an Angular application with a unique custom UI (Angular library) that is being built using PrimeNg.

The usual method I am following with PrimeNG looks like this:

// mac-login.html
<p-panel header="Login">
  <form (ngSubmit)="onSubmit()">
    <div class="p-field">
      <label for="username">Username</label>
      <input pInputText [(ngModel)]="username" id="username" name="username" required />
    </div>
    <div class="p-field">
      <label for="password">Password</label>
      <p-password [(ngModel)]="password" id="password" name="password" required />
    </div>
    <div class="p-field">
      <p-button type="submit" label="Login"></p-button>
    </div>
  </form>
</p-panel>

Additionally, my implementation can be seen below:

import { CommonModule } from '@angular/common';
import { Component, EventEmitter, Input, NgModule, Output } from '@angular/core';
import { PanelModule } from 'primeng/panel';
import { PasswordModule } from 'primeng/password';
import { InputTextModule } from 'primeng/inputtext';
import { ButtonModule } from 'primeng/button';
import { FormsModule } from '@angular/forms';

@Component({
  selector: 'mac-login',
  templateUrl: './mac-login.html',
  styleUrls: ['./mac-login.scss']
})
export class macLogin {
  @Input() username: string = '';
  @Input() password: string = '';

  @Output() submitForm: EventEmitter<{ username: string; password: string }> = new EventEmitter();

  onSubmit(): void {
    if (this.username && this.password) {
      this.submitForm.emit({ username: this.username, password: this.password });
    }
  }
}

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    PanelModule,
    InputTextModule,
    PasswordModule,
    ButtonModule
  ],
  exports: [ macLogin ],
  declarations: [ macLogin ]
})
export class macLoginModule {}

Upon attempting to use the component within my main app like so:

<mac-login
    [username]="user.email"
    [password]="user.password"
    (submitForm)="signIn()"
  ></mac-login>

And here:

import { Component } from '@angular/core';
import { Router } from '@angular/router';

import { IUser, AuthService } from '../../services/auth/cognito.service';

@Component({
  selector: 'app-sign-in',
  templateUrl: './sign-in.page.html',
  styleUrls: ['./sign-in.page.scss'],
})
export class SignInPage {

  loading: boolean;
  user: IUser;

  constructor(private router: Router,
              private authService: AuthService) {
    this.loading = false;
    this.user = {
      email: '',
      password: ''
    } as IUser;
  }

  public signIn(): void {
    this.loading = true;
    this.authService.signIn(this.user)
    .then(() => {
      this.router.navigate(['/profile']);
    }).catch(() => {
      this.loading = false;
    });
  }

}

An error message is displayed:

main.ts:6 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of null (reading 'firstCreatePass')
TypeError: Cannot read properties of null (reading 'firstCreatePass')
    at providersResolver (core.mjs:22359:15)
    at definition.providersResolver (core.mjs:22620:24)
    at initializeDirectives (core.mjs:11935:17)
    at resolveDirectives (core.mjs:11909:13)
    at elementStartFirstCreatePass (core.mjs:15677:5)
    at ɵɵelementStart (core.mjs:15713:9)
    at macLogin_Template (mac-login.html:1:1)
    at executeTemplate (core.mjs:11409:17)
    at renderView (core.mjs:12608:13)
    at renderComponent (core.mjs:12555:5)
    at resolvePromise (zone.js:1193:31)
    at resolvePromise (zone.js:1147:17)
    at zone.js:1260:17
    at _ZoneDelegate.invokeTask (zone.js:402:31)
    at core.mjs:27127:55
    at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:27127:36)
    at _ZoneDelegate.invokeTask (zone.js:401:60)
    at Object.onInvokeTask (core.mjs:27437:33)
    at _ZoneDelegate.invokeTask (zone.js:401:60)
    at Zone.runTask (zone.js:171:47)

I have verified the correct importation of the library in app.module.ts

The entire UI library is integrated through pnpm workspaces.

Is there any solution to overcome this error? Thank you.

Answer №1

After spending countless hours scouring forums and posts, I finally stumbled upon the solution that was far from obvious.

When dealing with pnpm workspaces and managing multiple Angular projects, a common issue arises with package management. This results in multiple instances of Angular Ivy being provided, causing a mismatch between the library's Ivy and the app's Ivy from node_modules - leading to chaos within the application.

To prevent this, it is crucial to ensure that both the app and connected libraries are exclusively using @angular from node_modules!

The setup process is quite simple. Just add the following snippet to your app's tsconfig.json:

{
  ...,
  compilerOptions: {
    ...,
    "paths": {
      "@angular/*": [
        "./node_modules/@angular/*"
      ]
    }
  }
}

And there you have it. Smooth sailing in Angular 16.2.0.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Application cannot locate the interface file

Attempting to create a basic test environment for the OMBD Api. Utilizing an interface file named ombdresponse.ts: interface IOMBDResponse { Title: string; Year: string; Director: string; Poster: string; } The issue arises within the ombd- ...

What are some strategies I can implement to effectively manage different errors and ensure the app does not crash

I came across a variety of solutions for error handling. The key concept revolves around this explanation: https://angular.io/api/core/ErrorHandler Attempts were made to implement it in order to capture TypeError, however, the outcome was not successful: ...

Having trouble importing SVG as a React component in Next.js

I initially developed a project using create-react-app with Typescript, but later I was tasked with integrating next.js into it. Unfortunately, this caused some SVGs throughout the application to break. To resolve this issue, I implemented the following pa ...

When you use .reset(), the form is cleared out, but the validation rules remain in

My reactive form includes a password field that I want to reset when the form is submitted. Despite using the .reset() method, my form still retains the classes ng-touched and ng-invalid. I'm unsure of where the issue lies. Here is a simplified versio ...

Difficulty encountered when assigning a value to an array within an object derived from a class

Within my Angular project, I've created a class: export class Test { mcq: { question: string, options:string[]}[] = []; } //outline of an object containing a question and an array of strings In another component where I import this class, I want t ...

Create a simulated class to serve as a property within a service

Currently, I'm working on an Ionic application and have created an AlertService class with two properties: messageAlert: Alert; errorAlert: Alert; The Alert class belongs to the Ionic framework, so I cannot modify it. To mock the Alert class, I came ...

fix IDE error when handling responses with async/await

I find myself facing a challenging scenario involving the use of promises (then|catch) for error handling, while also awaiting code cleanliness. Here's what I'm currently dealing with: let rules:Rules = await elb.describeRules(params).promise(). ...

Exploring subclasses in TypeScript

When working with TypeScript and defining an interface like the one below: export interface IMyInterface { category: "Primary" | "Secondary" | "Tertiary", } Can we access the specific "sub types" of the category, such as ...

The Angular 4 proxy configuration file is not properly directing to the specified target destination; instead, it is redirecting to localhost:4200

I'm having trouble with my Angular 4 proxy configuration file - it's not redirecting to the target I specified and instead is redirecting to <http://localhost:4200>. ...

Function being called from TypeScript in HTML is not functioning as expected

Hello, I am currently using Django and looking to implement TypeScript for a specific function within my application. Below is the content of my TypeScript file: testselector.ts: getSelectionText() { var text = ""; if (window.getSelection) { ...

Obtain the Accurate Error Response when Posting in Angular 5

My controller has validation in C# as shown below: if (user == null) { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return BadRequest(ModelState); } When I try ...

I aim to showcase div elements based on the specific Props value

My goal is to showcase the 'selected' option when the values consist of { query: string; isSelect: boolean } and the isSelect property is set to true. Error: The 'isSelect' property is not recognized in the type '{ query: string; ...

Angular Lifecycle Hook - Data loading initializes after the view initialization is complete

In my component, I have loaded a firestore document and converted it into a plain js object within the constructor. However, when trying to access the field values in the template, there is a slight delay in loading them. This results in an error being dis ...

Angular 8 is throwing an error stating that the property 'token' is not recognized on the 'Object' data type

As a newcomer to Angular, I have been following the MEAN Stack - Mean Auth App Tutorial in Angular 2. However, since I am using Angular 8, some of the code is deprecated due to recent updates. I have encountered an issue with the code bel ...

Angular subscription unsubscription issue

I have noticed that my Angular application has a significant amount of event hooks and subscriptions which are causing performance issues. Initially, the app functions well but after continued usage, it becomes slow with typing delays of around 2 to 3 seco ...

Issues with the Bootstrap Grid System not functioning correctly when inter-component communication is needed in Angular from parent to

This is the code from app.component.html file: <div class="container"> <div class="row" id="ads"> <div class="col-xs-4"> <app-card *ngFor="let car of cars" [carNotifyBadge]="car.carNotifyBadge" [ca ...

Is it possible for the button text to switch from Farewell to Greetings after two clicks?

There seems to be a strange issue in my React TS project - I have to click the button twice to switch the text from "Goodbye" to "Hello", but not the other way around. Any ideas why? import { useState } from 'react' const ChangeTextButton = () ...

Combining the power of Bootstrap and Google Material in Angular applications

I am currently utilizing Material and Flex, such as @angular/material and @angular/flex-layout Focusing on using Flex for creating responsive layouts. In search of a more refined approach to handle basic tasks like adjusting margins. Although I could si ...

What is the best way to handle a global path parameter in a Nest.js application?

Currently, I am in the process of constructing a rest API for a fully multi-tenant system using a single database and application. To achieve this, I have chosen NestJS as my framework of choice. My goal is to structure all modules based on the :tenantID t ...

Preserve Angular Material Mat Ripple Animation even after it has been clicked

When using mat-list with matRipple for click animations, the default behavior is for the ripple animations to disappear after a while. However, I want to keep the animation even after clicking so that the background color won't change. Is there a way ...