Universal: Event is not defined

Created on 11 Nov 2017  路  12Comments  路  Source: angular/universal

Note: for support questions, please use one of these channels: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports. Also, Preboot has moved to https://github.com/angular/preboot - please make preboot-related issues there.

  • I'm submitting a ...
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
  • What modules are related to this Issue?
- [ ] aspnetcore-engine
- [x] express-engine
- [ ] hapi-engine
  • Do you want to request a feature or report a bug?

bug

  • What is the current behavior?

when I upgrade from angular 5.0.0 to 5.0.1 EventManager was broken with ReferenceError: Event is not defined

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.
constructor(
    private eventManager: EventManager,
  ) {
  }

upgrade angular from 5.0.0 to 5.0.1

  • Please tell us about your environment:

  • Angular version: 5.0.1

  • Browser: [all]
  • Language: [all ]
  • OS: [all]
  • Platform: [NodeJs ]

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

ERROR { Error: Uncaught (in promise): ReferenceError: Event is not defined
ReferenceError: Event is not defined

Most helpful comment

me help global['Event'] = null; in server.ts

All 12 comments

it may be caused by document

I experienced this as well, it seems adding hostlistener may lead to this error too

please have a look at the https://github.com/wpcfan/universal-starter.git, I did not add any document/window stuff, just a directive with @HostListener, and it will cause the error

Thanks for reporting this, looks like a bug to me, will investigate.
@wpcfan if you remove the :Event then you error goes away

me help global['Event'] = null; in server.ts

Got the exact same error and after applying the fix from @Gorniv I get the same error just with FocusEvent and KeyboardEvent. I don't know what could cause this.

Removing the type fixes this

I met the same error when run node dist/server.js. I tried with domino by adding these lines in server.ts

const domino = require('domino');
const fs = require('fs');
const path = require('path');
const Zone = require('zone.js');
const DIST_FOLDER = path.join(process.cwd(), 'dist');
const template = fs.readFileSync(path.join(DIST_FOLDER, 'browser', 'index.html')).toString();
const win = domino.createWindow(template);
const files = fs.readdirSync(`${process.cwd()}/dist/server`);
import fetch from 'node-fetch';

win.fetch = fetch;
global['window'] = win;
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;
global['HTMLElement'] = win.HTMLElement;
global['navigator'] = win.navigator;
global['Event'] = win.Event;
global['Event']['prototype'] = win.Event.prototype;
Object.defineProperty(win.document.body.style, 'transform', {
    value: () => {
        return {
            enumerable: true,
            configurable: true
        };
    },
});
global['document'] = win.document;
global['CSS'] = null;

So the error disappeared, and I saw another one:
ERROR TypeError: Cannot assign to read only property 'stopImmediatePropagation' of object '[object Object]'

Use global['Event'] = null; just lead me to an other error:

ERROR { Error: Uncaught (in promise): Error: no Promise impl found
Error: no Promise impl found

Any solution for this case now?

I am experiencing this bug as well, but I use aspnetcore-engine.

I created a PR to fix some issues about Event is not defined in here, https://github.com/angular/angular/pull/22905.
@thovo, could you post a reproduce repo about this error

ERROR { Error: Uncaught (in promise): Error: no Promise impl found
Error: no Promise impl found

I am sorry that I can not reproduce for you a repository with that errors. But, to resolve my problem, I isolated the part which had the call with Event by wrapping everything in the condition of platformBrowser and it worked normally now. I hope it could help other with similar issues. Actually, I wrapped almost everything inside of platformBrowser to prevent error like above.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings