Skip to content
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

Trouble in Angular6 project with Typescript #18

Closed
zedzorander opened this issue Jul 28, 2018 · 10 comments · Fixed by #57
Closed

Trouble in Angular6 project with Typescript #18

zedzorander opened this issue Jul 28, 2018 · 10 comments · Fixed by #57

Comments

@zedzorander
Copy link

I'm sure i'm doing something dumb but I'm trying to use this in my project and I'm having trouble getting it to work. It says it can't find a declaration file and that the index.js file implicitly has an any type. I added this to my tsconfig file "noImplicitAny": false, but it's still giving me this warning. I'm importing it in my component like this: import * as PasswordValidator from '../../../node_modules/password-validator';. I've also tried it like this: import { PasswordValidator } from '../../../node_modules/password-validator';.

When I console log schema it gives me this error message..
ERROR TypeError: Cannot read property 'is' of undefined at AccountFormComponent.push../src/app/account-form/account-form.component.ts.AccountFormComponent.validatePassword (account-form.component.ts:67) at Object.eval [as updateRenderer] (AccountFormComponent.html:69) at Object.debugUpdateRenderer [as updateRenderer] (core.js:10879) at checkAndUpdateView (core.js:10255) at callViewAction (core.js:10491) at execComponentViewsAction (core.js:10433) at checkAndUpdateView (core.js:10256) at callViewAction (core.js:10491) at execEmbeddedViewsAction (core.js:10454) at checkAndUpdateView (core.js:10251)

I'm just using the example code in your README. Not sure where to go from here. Thanks

@tarunbatra
Copy link
Owner

Hey @zedzorander, thanks for reporting the issue.

I'm not well versed with TypeScript and Angular 6. The issue you mentioned doesn't look like an issue with password-validator, given it's pretty standard JavaScript module. I'll dig for possible reasons of this behaviour and update here, if any.

@zedzorander
Copy link
Author

zedzorander commented Jul 30, 2018

Yeah, my program isn't recognizing the module for some reason. I found some stuff which makes me think it needs a definition file for it to work. Here is an article I found that seems to be related to what I was experiencing. It might be a good start. https://academind.com/learn/angular/angular-q-a/#integrate-third-party-libraries. Thanks.

@tarunbatra
Copy link
Owner

Yes, the link you shared suggests a way to add libraries without any declaration file. In my understanding it should look something like:

import 'password-validator';
declare var PasswordValidator: any;

@Component({...})
export class MyComponent {...}

@mohan-murali
Copy link

I think the problem @zedzorander is facing is with ES6 imports. I used "import PasswordValidator from 'password-validator';" and it is working for me. Could you please check that?

@hajimurtaza
Copy link

Try this, it will work. @zedzorander

const passwordValidation = require('../../../node_modules/password-validator');

declare var doesnt work on lot of third party libraries, this will definately work.

@marcomartinscastanho
Copy link

+1 having troubles with Typescript.

I'm importing as
import PasswordValidator from "password-validator";

declaring the schema as
const passwordSchema = new PasswordValidator();

and getting the following error
TypeError: password_validator_1.default is not a constructor

@tarunbatra
Copy link
Owner

Hey @marcomartinscastanho thanks for describing your issue. I tried reproducing this but failed.

Here's a stackblitz url showing the password-validator being imported in a sample TypeScript project. Hopefully you will be able to resolve the issue. If not, can you share a reproducible example of the issue?

@khofesh
Copy link

khofesh commented Aug 3, 2021

+1 having troubles with Typescript.

I'm importing as
import PasswordValidator from "password-validator";

declaring the schema as
const passwordSchema = new PasswordValidator();

and getting the following error
TypeError: password_validator_1.default is not a constructor

same problem in nestjs,
error: TypeError: password_validator_1.default is not a constructor

tarunbatra added a commit that referenced this issue Oct 24, 2021
tarunbatra added a commit that referenced this issue Oct 24, 2021
@tarunbatra
Copy link
Owner

error: TypeError: password_validator_1.default is not a constructor

This error should be fixed in v5.1.2

@khaitranhq
Copy link

@tarunbatra I met this error with 5.3.0

+1 having troubles with Typescript.

I'm importing as import PasswordValidator from "password-validator";

declaring the schema as const passwordSchema = new PasswordValidator();

and getting the following error TypeError: password_validator_1.default is not a constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants