Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atob is not defined #120

Closed
Drevoed opened this issue Jul 15, 2020 · 4 comments
Closed

Atob is not defined #120

Drevoed opened this issue Jul 15, 2020 · 4 comments

Comments

@Drevoed
Copy link

Drevoed commented Jul 15, 2020

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
@chrisguttandin
Copy link
Owner

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.

@Drevoed
Copy link
Author

Drevoed commented Jul 15, 2020

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

@chrisguttandin
Copy link
Owner

chrisguttandin commented Jul 15, 2020

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.

@Drevoed
Copy link
Author

Drevoed commented Jul 15, 2020

Thank you!

@Drevoed Drevoed closed this as completed Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants