angular-cli: *Event/HTML*Element is not defined error in server build

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Angular CLI: 1.5.0
Node: 8.7.0
OS: win32 x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.2
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

  1. Create new app with ng new ....
  2. Follow https://github.com/angular/angular-cli/wiki/stories-universal-rendering.
  3. Add @HostListener('window:click') click(event: MouseEvent) { } in the app.component.ts.
  4. Run yarn run build:ssr && yarn run serve:ssr.

Repro: https://github.com/kevinphelps/angular-cli-issue-8412-repro

The log given by the failure.

ReferenceError: MouseEvent is not defined
    at C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:12684
    at Object.wQAS (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:12867)
    at l (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:149)
    at Object.aR8+ (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:7591)
    at l (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:149)
    at Object.bNRb (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:7978)
    at l (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:149)
    at Object.JwoV (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:995)
    at l (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:149)
    at Object.Zq8w (C:\Users\Kevin\Desktop\server-test\dist\server.js:129629:7299)

Desired functionality.

The use of Event, MouseEvent, KeyboardEvent, HTMLElement, etc. interfaces should not break the server builds.

Mention any other details that might be useful.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 18 (12 by maintainers)

Most upvoted comments

I just looked into this. There is something strange going on. The compilation and all works as expected. however, when the resulting server.JS is started, it blows up with the mentioned error.

The strange thing is: MouseEvent is used as a type. It should not end up in the JS at all!.
Changing it to type any fixes the current bug, but not in a way we would like to see.

Not sure what is the root cause of this is.