ReferenceError: btoa is not defined (during SSR)
See original GitHub issueWhat:
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:
- Created 5 years ago
- Comments:10 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kettanaito But for SSR in code still
return !('Proxy' in window)
.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 theProxy
is defined.