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.

window on server side undefined , hence Mousetrap is not defined

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

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)


- Node version: v7.0.0 
- npm version: 3.10.8  
- Operating System and version: MAC  
- Angular version: X.Y.Z 
- angular-cli version (or SystemJS/Webpack): X.Y.Z same as universal example
- I'm using Server Side Rendering with angular-universal: YES
- I'm compiling with mode: PROD with AOT



Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Others:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
Ks89commented, Mar 16, 2018

@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 😃

1reaction
istrdevcommented, Mar 5, 2018

Seems to work, need more time to fully test. Thank you for quick resolution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve this issue: Mousetrap is not defined error
I was trying to use the mousetrap.js library to enable certain keyboard commands on a website. I am using a js injector extension...
Read more >
How to solve "window is not defined" errors in React and Next.js
Because in the Node.js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1....
Read more >
Gatsby - the window is not defined error, what and how to fix it?
You can check if the browser-global object window is defined and based on it, execute the related code block. Copy. const isBrowser =...
Read more >
All of the Documentation | Electron - GitHub Pages
quit() , Electron will first try to close all the windows and then emit the will-quit event, and in this case the window-all-closed...
Read more >
Window is undefined during SSR - RichHewlett.com
This is because when the app is being rendered on the server side on the web server it is not within the browser...
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