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

Event is not defined #844

Closed
Gorniv opened this issue Nov 11, 2017 · 12 comments
Closed

Event is not defined #844

Gorniv opened this issue Nov 11, 2017 · 12 comments
Milestone

Comments

@Gorniv
Copy link

Gorniv commented Nov 11, 2017

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
@ychost
Copy link

ychost commented Nov 13, 2017

it may be caused by document

@wpcfan
Copy link

wpcfan commented Nov 14, 2017

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

@wpcfan
Copy link

wpcfan commented Nov 16, 2017

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

@Toxicable
Copy link

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

@Gorniv
Copy link
Author

Gorniv commented Nov 25, 2017

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

@josephjohansson
Copy link

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.

@patrickmichalina
Copy link
Contributor

Removing the type fixes this

@thovo
Copy link

thovo commented Feb 19, 2018

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?

@Flood
Copy link

Flood commented Mar 20, 2018

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

@JiaLiPassion
Copy link

I created a PR to fix some issues about Event is not defined in here, angular/angular#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

@thovo
Copy link

thovo commented Mar 21, 2018

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.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants