viclafouch / mui-file-input

A file input designed for the React library MUI
https://viclafouch.github.io/mui-file-input/
MIT License
77 stars 17 forks source link

Error [ERR_REQUIRE_ESM]: require() of ES Module #25

Closed cogniclickadmin closed 1 year ago

cogniclickadmin commented 1 year ago

Describe the bug Using the component causes the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /myapp/node_modules/mui-file-input/node_modules/pretty-bytes/index.js from /myapp/node_modules/mui-file-input/dist/mui-file-input.umd.js not supported.

Instead change the require of index.js in /myapp/node_modules/mui-file-input/dist/mui-file-input.umd.js to a dynamic import() which is available in all CommonJS modules.

To Reproduce Install the package import MuiFileInput Use the MuiFileInput in a page/component

Desktop (please complete the following information):

Additional context Changing the require in dist to import() fixed it.

WenLonG12345 commented 1 year ago

I have the same issue as well. Any solution?

randbytes commented 1 year ago

Exactly same problem appeared this week.

EndlessDev2016 commented 1 year ago

I got the same errors, so i tried it.

My team's Next.js project loads dynamic import components on page load. But in this case, module in tsconfig.json is automatically changed to CommonJS → esnext. (same errors...)

const MuiFileInput = Dynamic(
  () => import("mui-file-input").then((d) => d.MuiFileInput),
  {
    SSR: false,
  },
);

it worked fine without any errors. :)

viclafouch commented 1 year ago

Let me fix that

viclafouch commented 1 year ago

Fixed in 2.0.5