universal: Angular 9: Window is not defined
Description
Iβm trying to migrate my solution to the latest angular universal version from AU 8 and during execute npm run dev:ssr I get an error:
...\dist-server\main.js:193133
})(window, document, 'Hammer');
^
ReferenceError: window is not defined
In previous version of server.ts my collegue figure it out like below:
const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
const win = domino.createWindow(template);
const files = fs.readdirSync(`${process.cwd()}/dist-server`);
global['window'] = win;
Object.defineProperty(win.document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true,
};
},
});
global['document'] = win.document;
How should I set βwindowβ in the latest version of AU?
π₯ Exception or Error
frontend\universal\dist-server\main.js:193133
})(window, document, 'Hammer');
^
ReferenceError: window is not defined
at Object../node_modules/hammerjs/hammer.js (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:193133:4)
at __webpack_require__ (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:20:30)
at Object../src/app/app.module.ts (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:239184:1)
at __webpack_require__ (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:20:30)
at Object../src/app/app.server.module.ts (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:239343:22)
at __webpack_require__ (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:20:30)
at Object../src/main.server.ts (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:252541:27)
at __webpack_require__ (K:\Projekty\Traceabilit frontend\universal\dist-server\main.
js:20:30)
at Object../server.ts (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:238941:23)
at __webpack_require__ (K:\Projekty\Traceabilit frontend\universal\dist-server\main.js:20:30)
A server error has occurred.
node exited with 1 code.
π Your Environment
β@angular/animationsβ: β^9.0.2β, β@angular/cdkβ: β^9.0.1β, β@angular/commonβ: β^9.0.2β, β@angular/compilerβ: β^9.0.2β, β@angular/coreβ: β^9.0.2β, β@angular/formsβ: β^9.0.2β, β@angular/materialβ: β^9.0.1β, β@angular/platform-browserβ: β^9.0.2β, β@angular/platform-browser-dynamicβ: β^9.0.2β, β@angular/pwaβ: β^0.900.3β, β@angular/routerβ: β^9.0.2β, β@angular/service-workerβ: β^9.0.2β, β@nguniversal/commonβ: β^9.0.1β, β@nguniversal/express-engineβ: β^9.0.1β,
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 29
Problem was related to hammerjs, after changed it on @egjs/hammerjs solution is building