Amplitude-JavaScript
Amplitude-JavaScript copied to clipboard
Error with Webpack building the site
Using Gatsby (newest version), when I try to use gatsby build on my site that uses this library, I get a build error:
error Building static HTML failed
See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html
773 | if (windowLocalStorageAvailable()) {
774 | localStorage = window.localStorage;
> 775 | } else if (window.globalStorage) {
| ^
776 | // Firefox 2-3 use globalStorage
777 | // See https://developer.mozilla.org/en/dom/storage#globalStorage
778 | try {
WebpackError: ReferenceError: window is not defined
Currently, my fix is to just exclude the amplitude file when building HTML. It's happening because the window object doesn't exist at the stage of the build this occurs at.
You can make Webpack skip processing libraries that are not "SSR-ready" by adding a rule for them with a null-loader plugin: https://www.gatsbyjs.org/docs/debugging-html-builds/#fixing-third-party-modules