question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Universal: Element is not defined

See original GitHub issue

Hi there!

Thank you for this fantastic Angular wrapper of Fullcalendar.

Unfortunately it doesn’t seem to build with Angular Universal. Here’s a repo that reproduces the error:

https://github.com/martinsiden/fullcalendar-universal

Here’s the steps I took when creating the repo:

Fire up new Angular CLI project:

ng new fullcalendar-universal

Add Angular Universal:

ng add @nguniversal/express-engine --clientProject fullcalendar-universal

Test run without Fullcalendar:

npm run build:ssr && npm run serve:ssr

Install Fullcalendar:

npm i --save @fullcalendar/angular @fullcalendar/core @fullcalendar/daygrid

Adding Fullcalendar to app.module.ts:

imports: [
  ...
  FullCalendarModule
]

Adding fullcalendar to app.component.html and passing in dayGridPlugin to it.

Adding CSS to angular.json:

"styles": [
    "node_modules/@fullcalendar/core/main.css",
    "node_modules/@fullcalendar/daygrid/main.css",
    "src/styles.css"
],

Starting “normally” with:

npm start

But running via Universal with:

npm run build:ssr && npm run serve:ssr

fails with:

/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133941
    var matchesMethod = Element.prototype.matches ||
                    ^

ReferenceError: Element is not defined
at /workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133941:25
at /workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133842:13
at Object.<anonymous> (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133844:2)
at __webpack_require__ (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:20:30)
at /workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:142649:30
at Object.<anonymous> (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:142651:2)
at __webpack_require__ (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:20:30)
at Object.@fullcalendar/daygrid (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133311:18)
at __webpack_require__ (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:132835:30)
at Module../src/app/app.component.ts (/workspace/fullcalendar-universal/fullcalendar-universal/dist/server.js:133017:79)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
irustmcommented, Aug 19, 2019

@jovpet @ajayashok @amunir9

If you still have a similar problem, try using this starter: https://github.com/Angular-RU/angular-universal-starter/

If you’re still in trouble, write to me about it.

0reactions
hamzou247commented, Sep 30, 2021

Hello everybody,

I have been trying with all the proposed solutions but no luck. Does anyone get passed this error. I think i soved it somehow in the past but i have unfortunaltely lost the related code. Can anyone help me please? i’m using version 4.4.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular SSR: ReferenceError: Element is not defined #1315
Apparently the issue is that Angular Universal is executed in the server, therefore some of the browser APIs and capabilities might be missing...
Read more >
Angular Universal SSR ReferenceError: Element is not defined
The error that you've provided seems to be coming from some 3d party library, which is not adjusted to work with Universal and...
Read more >
Angular Universal: ReferenceError: window is not defined
This error can be caused by a reference to the Window object if you are rendering your application from a server like Node.js....
Read more >
Angular Universal: real app problems - InDepth.Dev
SSR issues in Angular · 1. Infinite page loading · 2. Lack of cache out of the box · 3. Server errors of...
Read more >
AngularJS to Angular concepts: Quick reference
Angular does not have a bootstrap directive. To launch the application in code, explicitly bootstrap the root module ( AppModule ) of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found