question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: btoa is not defined (during SSR)

See original GitHub issue

What:

Performing SSR with atomic-layout results into the following exception:

ReferenceError: btoa is not defined
    at /Users/azakharchenko/projects/pwa/node_modules/atomic-layout/lib/index.js:1224:3
    at /Users/azakharchenko/projects/pwa/node_modules/atomic-layout/lib/index.js:670:29
    at /Users/azakharchenko/projects/pwa/node_modules/atomic-layout/lib/index.js:263:14
    at Composition (/Users/azakharchenko/projects/pwa/node_modules/atomic-layout/lib/index.js:1264:24)
    at processChild (/Users/azakharchenko/projects/pwa/node_modules/react-dom/cjs/react-dom-server.node.development.js:2868:14)
    at resolve (/Users/azakharchenko/projects/pwa/node_modules/react-dom/cjs/react-dom-server.node.development.js:2792:5)
    at ReactDOMServerRenderer.render (/Users/azakharchenko/projects/pwa/node_modules/react-dom/cjs/react-dom-server.node.development.js:3172:22)
    at ReactDOMServerRenderer.read (/Users/azakharchenko/projects/pwa/node_modules/react-dom/cjs/react-dom-server.node.development.js:3131:29)
    at renderToString (/Users/azakharchenko/projects/pwa/node_modules/react-dom/cjs/react-dom-server.node.development.js:3598:27)
    at app.get (webpack:///./src/server/middleware/ssr/index.js?:42:96)

Why:

I believe btoa is a window method, and is not available on the client-side.

Environment:

  • atomic-layout version: 0.6.0

Expected behavior:

Atomic layout doesn’t result into errors during SSR of an application.

Suggestions

Replace btoa with a lightweight hash generator package (or write your own in the sources)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
lokhmakovcommented, Feb 11, 2019

@kettanaito But for SSR in code still return !('Proxy' in window).

1reaction
kettanaitocommented, Feb 10, 2019

Thanks for double checking, @lokhmakov. I already have the fix on my branch. Let me write a test and merge.

I would prefer to use a local util rather than mutating a global variable:

https://github.com/kettanaito/atomic-layout/blob/20ae2182123620b312be0ef5ce677502a698e188/src/utils/strings/btoa.ts#L1-L7

The window error is related to the safety check whether the Proxy is defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js throws "btoa is not defined" error - Stack Overflow
ReferenceError : btoa is not defined. while Buffer is not defined on the client. I couldn't check window.btoa (it's a shared code, remember?)...
Read more >
Node.js - btoa is not defined error - Dirask
I tried to encode text to base64 using btoa function in Node.js, but I get this error: My code: How to solve it?...
Read more >
Error: btoa is not defined · Issue #101 · Zulko/eagle.js - GitHub
I keep getting this error at build time when creating static versions of this Vue app. Not sure what this function/variable is meant...
Read more >
WebpackError: ReferenceError: btoa is not defined
Getting this error when building in a dev environment using GatsbyJS: ERROR There was an error compiling the html.js component for the ...
Read more >
Btoa method is not defined - Freshworks Developer Community
If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means 'x' is either a variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found