TypeError: Cannot read property 'getContext' of undefined
See original GitHub issueHello am trying to retrieve one record from the database am getting this error “TypeError: Cannot read property ‘getContext’ of undefined”. What could be the issue?
Below is my code in an entity repository that’s being called in a service in Nest Js Framework
async validateUserPassword(signInCredentialsDto: SignInCredentialsDto): Promise<LoginUsers | null> { const { email, password } = signInCredentialsDto; const user = await this.em.findOne(LoginUsers, { email: email }) console.log(user) if(user && await user.validatePassword(password)){ return user; }else{ return null; } }
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Cannot read property 'getContext' of null, using canvas
I get the error Uncaught TypeError: Cannot read property 'getContext' of null and the important parts in files are... I am wondering since...
Read more >TypeError: Cannot read property 'getContext' of Null in JS
The "Cannot read property 'getContext' of null" error occurs when calling the getContext method on a null value. To solve the error, make...
Read more >Uncaught typeerror cannot read property 'GETCONTEXT' of null
The video shows how to correct the error when drawing on a canvas html5 "Uncaught typeerror cannot read property 'GETCONTEXT' of ...
Read more >Why is my code not going through? it's indicating ... - Sololearn
it's indicating >>> uncaught TypeError! cannot read property 'getContext' of null line: 5. var canvas= document.getElementById("canvas"); var contex= canvas.
Read more >Cannot read properties of null (reading 'getContext') - GSAP
Hi, I'm getting console errors "Cannot read properties of null (reading 'getContext')" and I'm not sure how to correct. My code is below....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is an example on how to get this error.
If you have a module of an entity
Foo
and also have a repository forFoo
, you would have something like thisAnd in the module you would need to use
MikroOrmModule.forFeature
to register the entity and repository (usingEntityRepositoryType
in the entity), which would look something like:Later you think something like “I want to use this repository in other module, so I will export it” and you will do:
and in another module you would import
FooModule
and add to the constructor of your serviceFooRepository
.And this is what will cause the error when trying to use the repositories in difference places.
I’m not sure if this is intentional or if it’s a bug/something not possible to do (Maybe @B4nan could say something about it).
To solve this you need to remove the
FooRepository
fromproviders
andexports
from theFooModule
and to use it in theBarModule
you must useMikroOrmModule.forFeature
to registerFoo
entity and it’s repository.This worked for me and hope this comment is good for people in the future.
I had the same problem, in my case I was declaring my custom repository as a provider and also importing it in the module configuration. Removing the repository from the providers array solved it.