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.

Module causes errors in prerendered application

See original GitHub issue

I’m submitting a …

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

Current behavior When importing the module in an application that uses prerendering, loading the application will fail, even if the ngx-datatable component is not used anywhere, but merely imported.

Expected behavior Any page should be able to prerender, regardless of whether the ngx-datatable component is on it or not. It’s ok for the ngx-datatable component itself to just prerender to an empty element.

Reproduction of the problem

  • Setup a dotnetcore application with ASP.NET Core 2.0 & Angular 5+
  • npm install ngx-datatable
  • Import NgxDatatableModule in app.module.ts
  • Try to start the application

What is the motivation / use case for changing the behavior? ngx-datatable is currently unusable in an application that uses prerendering, not even for the parts that are not prerendered. This can be easily fixed by checking the window variable before using it:

export const MouseEvent = ((window as any) || (global as any)).MouseEvent as MouseEvent;
export const KeyboardEvent = ((window as any) || (global as any)).KeyboardEvent as KeyboardEvent;
export const Event = ((window as any) || (global as any)).Event as Event;

This should become something like:

export const MouseEvent = (((typeof window !== 'undefined' && window) as any) || (global as any)).MouseEvent as MouseEvent;
export const KeyboardEvent = (((typeof window !== 'undefined' && window) as any) || (global as any)).KeyboardEvent as KeyboardEvent;
export const Event = (((typeof window !== 'undefined' && window) as any) || (global as any)).Event as Event;

Please tell us about your environment: Windows 10, Visual Studio 2017 Community Edition, dotnetcore 2.0

  • Table version: 11.3.2

  • Angular version: 5.0.0

  • Browser: platformBrowser (server side)

  • Language: TypeScript 2.6

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
GrimaceOfDespaircommented, Jun 7, 2018

For now, I’m working around this with webpack. Ugly, but it does the job. Note that I use 3 identical replacements to replace the three occurrences.

    module: {
        rules: [
            {
                test: /\.(ts|js)$/, use: {
                    loader: 'string-replace-loader', options: {
                        multiple: [{
                            search: '(window || global)',
                            replace: '((typeof window !== \'undefined\' && window) || global)'
                        }, {
                            search: '(window || global)',
                            replace: '((typeof window !== \'undefined\' && window) || global)'
                        }, {
                            search: '(window || global)',
                            replace: '((typeof window !== \'undefined\' && window) || global)'
                        }]
                    }
                }
            }
        ]
    }
2reactions
xstation1021commented, May 24, 2018

exports.MouseEvent = (window || global).MouseEvent; ^ ReferenceError: window is not defined

We also have a similar issue. NodeJS Table version: 13.0.0 Angular 5/ Angular Universal TypeScript 2.6

Read more comments on GitHub >

github_iconTop Results From Across the Web

1 - Stack Overflow
While I am compiling the angular code for prerendering below error is coming. ERROR in prerender.ts(7,62): error TS2307: Cannot find module ...
Read more >
Page options • Docs • SvelteKit
If you encounter an error like 'The following routes were marked as prerenderable, but were not prerendered' it's because the route in question...
Read more >
Prerendering - HubSpot Developers
Prerendering is where the HubSpot CMS makes a static version of your website page, landing page, blog post or knowledge base article.
Read more >
Cannot use import statement outside a module-angular.js
[Solved]-Prerendering causes a SyntaxError: Cannot use import statement outside a module-angular.js ... As stated here: Current node.js stable releases do not ...
Read more >
Server-Side Rendering (SSR) - Vue.js
Pre-rendered pages are generated and served as static HTML files. SSG retains the same performance characteristics of SSR apps: it provides great ...
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