Git Product home page Git Product logo

Comments (5)

telmaco avatar telmaco commented on June 6, 2024 2

I am not sure this will help you guys, but it worked for me.
I am using universal and got the same error (ReferenceError: KeyboardEvent is not defined) with the ng-gallery when running the build.

so first:

  1. install regexp-replace-loader:
    npm install regexp-replace-loader --save-dev

  2. then in weback.server.config.js add the below to the module > rules section:

module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader' },
      //below is the fix for image gallery keyboard error
      { test: /\.(ts|js)$/, 
        loader: 'regexp-replace-loader', 
        query: { 
            match: { 
                pattern: '\\[(Mouse|Keyboard)Event\\]', 
                flags: 'g' }, 
                replaceWith: '[]', 
            } 
        } 
    ]
  },
  1. on your gallery component wrap the gallery.load with the isPlatformBrowser:
import { Component, Inject, OnInit, } from '@angular/core';
import { PLATFORM_ID }   from '@angular/core';  //<--  if browser
import { isPlatformBrowser, isPlatformServer } from '@angular/common';//<--  if browser
import { Gallery }  from 'ng-gallery';   //<-- image gallery

@Component({
    selector:    'image-gallery',
    templateUrl: './image-gallery.component.html',
})

export class ImageGalleryComponent implements OnInit {
        {
          src: 'images/logo.png',
          thumbnail: 'images/logo.png',
          text: 'ccc'
        },
        // ...
    ];

    constructor(
        public gallery: Gallery,
        @Inject(PLATFORM_ID) private platformId: Object //<-- if browser
    ) { }

    ngOnInit() {
        if (isPlatformBrowser(this.platformId)) { //<-- if browser
            this.gallery.load(this.images);
        }
        if (isPlatformServer(this.platformId)) {}        
    }
} 

Hope it will help someone as it helped me.
Cheers

from ngx-gallery.

MurhafSousli avatar MurhafSousli commented on June 6, 2024

Is this error showing in the building process or at runtime? please post the full error

from ngx-gallery.

MarianoFranzese avatar MarianoFranzese commented on June 6, 2024

I have the same error on angular 5.0.2 and universal 5.0.0-beta.5

/usr/src/app/dist/server.js:149337
    __metadata$1("design:paramtypes", [KeyboardEvent]),
                                       ^

ReferenceError: KeyboardEvent is not defined
    at Object.<anonymous> (/usr/src/app/dist/server.js:149337:40)
    at __webpack_require__ (/usr/src/app/dist/server.js:20:30)
    at Object.9QXJ (/usr/src/app/dist/server.js:146313:29448)
    at l (/usr/src/app/dist/server.js:146313:149)
    at Object.pfyn (/usr/src/app/dist/server.js:146313:161422)
    at l (/usr/src/app/dist/server.js:146313:149)
    at Object.5tsa (/usr/src/app/dist/server.js:146313:28218)
    at l (/usr/src/app/dist/server.js:146313:149)
    at Object.JwoV (/usr/src/app/dist/server.js:146313:98938)
    at l (/usr/src/app/dist/server.js:146313:149)

from ngx-gallery.

CosmoFruit avatar CosmoFruit commented on June 6, 2024

Thx, its work!

from ngx-gallery.

adrienlamotte avatar adrienlamotte commented on June 6, 2024

+1
Angular Universal support needed :)

from ngx-gallery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.