[Solved] ReferenceError: KeyboardEvent is not defined

[Solved] ReferenceError: KeyboardEvent is not defined

This error happens due to lot of reasons.

In my case I was getting this error while making my angular site to angular universal site for server side rendering and better SEO.

But when I was trying to convert to angular universal I got this “ReferenceError: KeyboardEvent is not defined ” issue.

In my case it was because of ngx-bootstrap component. In particular I used rating component from ngx-bootstrap and exactly in that module I got this error.

I just commented out those things and ran npm run start and it works fine.

And I came across a below link which actually suggests to built angular universal with ngx-bootstrap using webpack, details are at the below link,

https://github.com/ranavc32/SimpleMDE-angular-universal/pull/2/commits/193f4a8c58e01a2b55764532d7e3ca8101d312ec

But it did not work out for me at this time.

I also see similar issues with ngx-bootstrap for angular universal support in github issues section. Looks their new version resolves. If someone checked and it works fine, then keep updated in the below comments section to help someone. Else I will come back with the new posts.

Leave a Reply