-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
window on server side undefined , hence Mousetrap is not defined #125
Comments
Hi, thank you for reporting this, but it's well known. This happens because I'm using mousetrap, a very powerful js library to catch keyboard actions. This lib is built with the 'window' object like most of the js library before es6. At the moment, I cannot do anything because this is an issue of angular universal (or a missing feature). Google is working on this so we should wait and hope for a quick solution. PS there is another possibility but I don't know how to implement it. I should inject my mousetrap service only on clients. I don't know if it is possibile or not. Do you have any suggestions? Would you try to fix this issue? If yes, any contribution will be well accepted. |
Oh I didn't see you solution above. Did you try it? Is it really working? |
Ok, I found a workaround based on your solution. |
Released as 5.2.0-beta.1. Could you try if it is working now? To install use 'npm i --save angular-modal-gallery@5.2.0-beta.1' |
Seems to work, |
Hi! |
I pushed 5.2.0. If you find a bug, please add a comment to this issue |
@istrdev I close this issue, because I already released 5.2.0. If you have problems or bugs, add a comment here. |
I am still facing this issue. I am was following this universal example which uses "domino" that creates a server-side DOM and a global "window" object with it. |
did you try my official universal example? |
PS: this tutorial is not working https://github.com/Angular-RU/angular-universal-starter The only working solution that I found is with your suggestion to require mousetrap inside an if. Check my example for more info. |
Your example assumes there is no window object This is the logic in my server.ts is as follows:
The part I've added is a global "Mousetrap" constructor so the server starts without errors. Not sure if this is the right way, but it fixes the issues for me.
|
@mrVers I'll check this weekend. SSR has many missing features so I suppose that can add your workaround without problems. Obviously I'll remove everything when Google will release a serious version of angular-universal :) |
@mrVers did you add this
on server-side or inside angular-modal-gallery source code? |
I've added it on the server-side |
Ahh Ok ok, yes on server side is right to do some stuff like that. It's a workaround, but it's like most of all others required to run SSR without errors. angular-universal is still too young and without a full window implementation on server-side is quite useless/boring. At the moment I cannot do anything inside the lib to prevent this type of issues. But your suggestion to check for
could be a good idea. If you confirm that it's really working I can suggest it on the doc as a temporary workaround for users that are using this:
|
Issue closed, however when @mrVers will confirm this workaround:
I'll update the doc |
@Ks89 yeah, it works on my end 👍 |
I'm submitting a...
Current behavior
when running universal example
https://github.com/Ks89/angular-modal-gallery/tree/master/examples/universal
npm run build:ssr && npm run serve:ssr
getting error on server side:
Node Express server listening on http://localhost:4000
ERROR { Error: Uncaught (in promise): ReferenceError: Mousetrap is not defined
ReferenceError: Mousetrap is not defined
at new KeyboardService
Expected behavior
no error
Minimal reproduction of the problem with instructions
My official live example on StackBlitz (based on https://stackblitz.com/edit/angular-modal-gallery-v5) is:
What is the motivation / use case for changing the behavior?
gallery is working in browser , but it breaks other stuff for me server-side : specifically translation
had to revert to previous working version of gallery 4.0.1
although using it with wrappers -
var implementation = function () { };
if (typeof window !== 'undefined') {
implementation = require('mousetrap');
}
module.exports = implementation;
Environment (the most important section to fill very carefully)
The text was updated successfully, but these errors were encountered: