atob polyfill fails during build on Node 16 with ReferenceError: window is not defined
See original GitHub issueGeneral information
https://github.com/braintree/braintree-web/blob/main/src/lib/vendor/polyfill.js (commit: cf1b052cc7ddff4ffa62b8da69674ac5d663e0e3)
Issue description
Node 16 ships with atob and btoa global functions, whereas Node 14 does not.
On our build machine with Node 16 we tried building a Next.js project which uses braintree-web. braintree-web/blob/main/src/lib/vendor/polyfill.js runs as part of the build process, and it fails at this line:
var atobNormalized = typeof atob === 'function' ? window.atob : atobPolyfill;
The problem here is that in NodeJS 16 atob is defined, and therefore it tries to get it from window.atob, which fails with ReferenceError: window is not defined
because window is not defined during the build process.
#11 76.82 > Build error occurred
#11 76.82 ReferenceError: window is not defined
#11 76.82 at Object.<anonymous> (/app/node_modules/braintree-web/lib/vendor/polyfill.js:3:51)
#11 76.82 at Module._compile (node:internal/modules/cjs/loader:1109:14)
#11 76.82 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
#11 76.82 at Module.load (node:internal/modules/cjs/loader:989:32)
#11 76.82 at Function.Module._load (node:internal/modules/cjs/loader:829:14)
#11 76.82 at Module.require (node:internal/modules/cjs/loader:1013:19)
#11 76.82 at require (node:internal/modules/cjs/helpers:93:18)
#11 76.82 at Object.<anonymous> (/app/node_modules/braintree-web/lib/create-authorization-data.js:3:12)
#11 76.82 at Module._compile (node:internal/modules/cjs/loader:1109:14)
#11 76.82 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) {
#11 76.82 type: 'ReferenceError'
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Node.js throws "btoa is not defined" error - Stack Overflow
The new directory showed up in my node_modules folder, which itself is in root alongside app.
Read more >How to solve "window is not defined" errors in React and Next.js
First solution: typeof Rogier Nitschelm for reminding me about this. I initially tried to do if (typeof window !== undefined) and this failed...
Read more >How To Solve ReferenceError window is not defined in ...
Fixing a window is not defined error can be quite simple. In most cases, all you will need to do is wrap your...
Read more >Firebase JavaScript SDK Release Notes - Google
Fixed a bug where error.email and other fields were not populated in the Google Sign-In error flow if the user had been disabled...
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 >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
This is fixed in v3.79.0
Yeah we are using Node 14 for now. Thanks!