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.

Not rendering in Universal: MouseEvent undefined

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior Unable to render Number Card or Pie Grid in universal.

Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: MouseEvent is not defined

Expected behavior NgxChartsModule should build in AOT and render in universal.

Reproduction of the problem Based on: #441

What is the motivation / use case for changing the behavior? Declare MouseEvent:

force-directed-graph/force-directed-graph.component.ts

// tslint:disable-next-line:variable-name
declare const global: any;
// tslint:disable-next-line:variable-name
const MouseEvent = (global as any).MouseEvent as MouseEvent;

@Component({
  selector: 'ngx-charts-force-directed-graph',

common/area-tooltip.component.ts

// tslint:disable-next-line:variable-name
declare const global: any;
// tslint:disable-next-line:variable-name
const MouseEvent = (global as any).MouseEvent as MouseEvent;

@Component({
  selector: '[ngx-charts-area-tooltip]',

Fixes based on ngx-bootstrap package: https://github.com/valor-software/ngx-bootstrap/commit/d20ccf109c9a718823b2eab4f971b3595b04a83f

Please tell us about your environment: MacOS Sierra 10.12.5 VS Code Yarn: 0.24.6 Webpack: 3.0.0

  • ngx-charts version: 5.3.1
  • Angular version: 4.2.4
  • Browser: all
  • Language: TypeScript 2.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
blue-cpcommented, Nov 21, 2017

@nukec - I found this hack here and I got it to work

first install

npm install regexp-replace-loader --save-dev

then in weback.server.config.js add below in modules.rules section

{
        test:/\.(ts|js)$/,
        loader:'regexp-replace-loader',
        options:{
          match:{
            pattern:'\\[(Mouse|Keyboard)Event\\]',
            flags:'g'
          },
          replaceWith:'[]',

        }
      }

Hope this helps.

4reactions
sambercommented, Feb 8, 2018

Working with domino:

// server.ts

const domino = require('domino');

const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['MouseEvent'] = win.MouseEvent;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Universal: MouseEvent is not defined - Stack Overflow
Every direct calls to document or window object will result in an error once you render your page with the ssr (those are...
Read more >
Developers - Not rendering in Universal: MouseEvent undefined -
Not rendering in Universal : MouseEvent undefined ; I'm submitting a ... (check one with "x") ; Current behavior. Unable to render Number...
Read more >
Server side rendering (universal) impossible. (KeyboardEvent
Hello, Do you have a fix for the rendering problem with server with universal. For a website this is essential for SEO, is...
Read more >
"MouseEvent" not defined - server side rendering
Hi, This is not PrimeNG problem. This is about angular universal. If you build with https://github.com/angular/universal-starter then you will ...
Read more >
Server-side Rendering (SSR) with Angular Universal
JavaScript apps can be rendered and indexed on Google, but not all search engines are as advanced. Social media networks like Facebook only...
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