I've got an angular 7.2 app using open layers 5.3. I'm trying to set up angular universal for this app, but when I run the universal server (node dist/server.js
), I got some errors due to client only variables not being defined, such as window
.
webpack:///./node_modules/ol/has.js?:54
var DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1;
^
ReferenceError: window is not defined
I tried using domino to mock these variables, but it just fails with another error, because of a canvas element
Error: NotYetImplemented
at HTMLCanvasElement.exports.nyi (/my/project/dist/server.js)
All the OL code is imported and used in a single MapComponent
component. My imports look like this in this component:
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
My main problem is that the mentionned errors occur as soon as I run the universal server, so even before trying to access the universal rendered website in a browser.
Consequently, using something like this to only instantiate MapComponent
when the app is running client side does not work, since the crash occurs before that
<app-map *ngIf="isBrowser"></app-map>
where the isBrowser
variabled is initialised in the component with the value of isPlatformmBrowser(platformId)
Any suggestions?