Amplitude-JavaScript icon indicating copy to clipboard operation
Amplitude-JavaScript copied to clipboard

Error with Webpack building the site

Open ryandrew14 opened this issue 6 years ago • 1 comments

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.

ryandrew14 avatar May 05 '19 07:05 ryandrew14

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

davilima6 avatar Nov 26 '19 21:11 davilima6