mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[DataGrid] Exception "require is not defined" error whilst using Snowpack to build.

Open AdamCraven opened this issue 6 years ago • 1 comments

When including the index.esm.js module in Snowpack, the grid fails to load and an error occurs.

  • [X] The issue is present in the latest release.
  • [X] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When importing DataGrid into the application an error is displayed:

Uncaught ReferenceError: require is not defined at data-grid.js:48

Expected Behavior 🤔

No error should be displayed, data-grid should load.

Steps to Reproduce 🕹

Unforunately I cannot create a Snowpack environment on a playground, but I can see the exact code that is causing it:

index-esm.js 16 col 13992 so=require("events").EventEmitter

The require call shouldn't exist in the ESM file, as require doesn't work in ESM files, only commonJS files.

The developer of Snowpack explains why:

"Usually this happens when a package tells us that it's ESM but it then still contains CJS require() calls. If a package tells us it's ESM we'll trust it, but in some cases that's not true." - https://github.com/pikapkg/snowpack/discussions/1321 . Webpack seems to auto correct it

Context 🔦

Attempting to run data-grid for the first time in a snowpack enviroment.

Your Environment 🌎

Tech Version
@material-ui/core v4.11.0
@material-ui/data-grid v4.0.0-alpha.6
snowpack 2.10.0
react 16.8.0
Browser 85.0.4183.83

PS: Hi @dtassone - I hope you are well :)

AdamCraven avatar Oct 16 '20 16:10 AdamCraven

This should be fixed in the next release v4.0.0-alpha.9 (once shipped).

oliviertassinari avatar Oct 29 '20 20:10 oliviertassinari