chrisguttandin / angular-prerender

A command line tool to prerender Angular Apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Atob is not defined

Drevoed opened this issue · comments

When using angular-prerender with angular 9 application, it crashes on

.../node_modules/zone.js/dist/zone-node.js:192
throw error;

ReferenceError: atob is not defined

Hi Kirill, is it possible that you're using atob somewhere in your Angular app or that it's used by one of your dependencies? atob and btoa are not available in Node.js.

Yes, I do indeed use atob in one route, but it seems like my options here are limited to excluding a route, right?

You could create a little helper which uses the API of the current platform.

import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

export class Base64Service {

    constructor(private @Inject(PLATFORM_ID) platformId: Object) { }

    public atob(value: string): string {
        return isPlatformBrowser(platformId)
            ? atob(value)
            : Buffer.from(value).toString('base64');
    }

}

Or you replace the corresponding service, component, ... by using the DI of the AppServerModule.

Thank you!