I am trying to create an angular universal project with Materialize css. Everything works fine when I try to serve it using 'ng serve'. When I create a build and serve the build, It gives me an error 'window is not defined'. I have used Domino, but no success. I have also tried using window from '@ng-toolkit/universal', still the result is same.
If I install materialize css in a freshly generated angular universal project and run its build, everything works fine. The error comes when I try to initialize any components from materialize-css. The source of the error is the materialize script file - materialize.js. I have tried setting it up using cdn, by downloading materialize folder from the its home page as well as by installing materialize-css by npm. But it fails in all the three scenarios.
The error is:
/home/chinmay/matPro/dist/server.js:114848
var _get=function t(e,i,n){null===e&&(e=Function.prototype);var s=Object.getOwnPropertyDescriptor(e,i);if(void 0===s){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,i,n)}if("value"in s)return s.value;var a=s.get;return void 0!==a?a.call(n):void 0},_createClass=function(){function n(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}}();function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&
ReferenceError: window is not defined
at Object../src/assets/materialize/js/materialize.min.js (/home/chinmay/matPro/dist/server.js:114848:1135)
at __webpack_require__ (/home/chinmay/matPro/dist/server.js:114535:30)
at Object../src/app/app.component.ts (/home/chinmay/matPro/dist/server.js:114729:9)
at __webpack_require__ (/home/chinmay/matPro/dist/server.js:114535:30)
at Object../src/app/app.server.module.ngfactory.js (/home/chinmay/matPro/dist/server.js:114794:10)
at __webpack_require__ (/home/chinmay/matPro/dist/server.js:114535:30)
at Object../src/main.server.ts (/home/chinmay/matPro/dist/server.js:114892:37)
at __webpack_require__ (/home/chinmay/matPro/dist/server.js:114535:30)
at Object.0 (/home/chinmay/matPro/dist/server.js:114913:18)
at __webpack_require__ (/home/chinmay/matPro/dist/server.js:114535:30)
Any help would be appreciated.