material-table: 'WebpackError: ReferenceError: window is not defined' when building a static site using gatsbyjs

Using the current version of material-table it is not possible to build out a static html side (for example using gatsby js) During the build process the error WebpackError: ReferenceError: window is not defined shows up. I’m using “material-table”: “^1.62.0”,

It was working on an older version of material-table: https://codesandbox.io/s/yj6jnmqpw9?file=/package.json but seems to be broken by something introduced in the meantime. There are some leads on the gatsby side, but not enough to fix the error: https://www.gatsbyjs.org/docs/debugging-html-builds/#how-to-check-if-code-classlanguage-textwindowcode-is-defined

Any help is greatly appreciated

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Same issue with NextJS

Yeah, i confirmed this bug.

The problem is jsPDF. Related to Angular universal does not work with jsPDF: ReferenceError: window is not defined

It is not material-table fault, but probably not published new version until above issue fixed ?

Currently i am not using PDF Export, should it be this feature optional, not need to force it into material-table core ? just my 2 cents

Thanks @floAr , i also confirmed this PR works with Gatsby.

But for me, i will stick to material-table 1.62.0 because that version had all i need for my current project.

I will upgrade only if my project needs PDF Export function or material-table becomes more modular or at least has an option to choose which export function suites your need.

Probably instead: exportButton: true

We can use something like:

exportButton: {
    exportCsv: true,
    exportPdf: true
}

I have this problem with Nextjs - reverting to version material-table 1.62.0 for now.

There is a PR (#2114) that sould solve this problem, @mbrn maybe you want to have a look on this?

Experiencing the same thing with SSR - just going to revert to 1.62.0 until this is resolved

Yeah this is pretty critical—means any use of Material Table in a project with server-side rendering (SSR) could break, especially considering this was released on a minor version bump (so folks deployment processes may automatically bump to this version).

Agree — would be nice to have the ability to turn off the PDF version. Hitting the same issue with a Gatsby site

@oze4 I created a quick fix for this and confirmed it is working for the gatsby stack