0

I've been using msal.js for authentication in my Angular application. This is working fine for development builds using ng serve. Unfortunately this library gives me an error when I try to run a server build using node. This build is generated using npm run build:prod and served by using npm run server. After attempting to serve this using node, the following error occurs:

    /Users/mikey/Documents/projectname-angular8/dist/server.js:170525
class WindowWrapper extends Window {
                            ^

ReferenceError: Window is not defined
    at Module.<anonymous> (/Users/mikey/Documents/projectname-angular8/dist/server.js:170525:29)
    at __webpack_require__ (/Users/mikey/Documents/projectname-angular8/dist/server.js:21:30)
    at Object.@azure/msal-angular/dist/msal.module (/Users/mikey/Documents/projectname-angular8/dist/server.js:148059:18)
    at __webpack_require__ (/Users/mikey/Documents/projectname-angular8/dist/server.js:141641:30)
    at Object../src/app/app.server.module.ngfactory.js (/Users/mikey/Documents/projectname-angular8/dist/server.js:142963:13)
    at __webpack_require__ (/Users/mikey/Documents/projectname-angular8/dist/server.js:141641:30)
    at Object../src/main.server.ts (/Users/mikey/Documents/projectname-angular8/dist/server.js:147883:37)
    at __webpack_require__ (/Users/mikey/Documents/projectname-angular8/dist/server.js:141641:30)
    at Object.0 (/Users/mikey/Documents/projectname-angular8/dist/server.js:147904:18)
    at __webpack_require__ (/Users/mikey/Documents/projectname-angular8/dist/server.js:141641:30)

I can understand why the error is happening, but as this third party library is required, I am unable to remove this package from the project all together. I've tried only loading this part of the code in app.browser.module.ts but then I am having injection errors when attempting to run the server side version in the browser.

I hope someone can explain me how I can make a runnable server side build of this project while using this third party library.

Mikey123
  • 1,201
  • 2
  • 12
  • 23
  • Did you get anywhere with this? – thefenry Feb 24 '20 at 19:47
  • 1
    @thefenry Unfortunately not. Only solution was to use the original msal.js version in my angular project instead of the angular wrapper, which seems to be working fine now as we use it in production. Don't expect any help on the wrapper from the developers, they seem to be very slow updating the wrapper as angular 6 is still not actively supported.. – Mikey123 Feb 25 '20 at 10:37
  • Ah bummer. Did you experience any infinite loop issues with the msal library? – thefenry Feb 27 '20 at 02:25
  • @thefenry Yes I had, that usually happens when you have an invalid redirect url. Worth checking if it is configured correctly in your Azure portal and the MSAL config (do note it has to be HTTPS). But I suggest opening a new question for that if the url's are correctly configured. – Mikey123 Feb 28 '20 at 10:19

0 Answers0