Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Serialized Error: { code: 'ERR_UNSUPPORTED_DIR_IMPORT' } #6086

Open
Gbolade-True opened this issue Jun 27, 2024 · 5 comments
Open

[BUG] - Serialized Error: { code: 'ERR_UNSUPPORTED_DIR_IMPORT' } #6086

Gbolade-True opened this issue Jun 27, 2024 · 5 comments
Labels

Comments

@Gbolade-True
Copy link

Describe the bug

Directory import `node_modules/@mui/material/Box` is not supported resolving ES modules imported from `node_modules/@refinedev/mui/dist/index.mjs`.

After extensive research, I found out that Node.JS doesn't support Directory imports. At least not yet. This is an issue with the latest release of the @refinedev/mui library. It imports Material UI components via directories.

This error was noticed when running tests using vitest in my application.

Steps To Reproduce

  1. Setup a basic React application with Vite and install latest release of necessary dependencies for refine:
"@refinedev/core": "^4.51.0",
"@refinedev/mui": "^5.17.0",
  1. Setup standard configurations for vitest after installing vitest , @testing-library/dom, @testing-library/jest-dom, @testing-library/react, and @vitejs/plugin-react.
  2. Create a basic test file. App.test.tsx
  3. Run vitest and see the error in the terminal.

Expected behavior

I expected the tests to run properly. If there were no Directory imports in the node_modules/@refinedev/mui/dist/index.mjs file, there wouldn't have been an issue. A minor fix to move from directory imports to file imports will be good and following the standards set by Node.JS

Packages

"@refinedev/core": "^4.51.0",
"@refinedev/mui": "^5.17.0",
"@refinedev/react-hook-form": "^4.8.20",
"@refinedev/react-router-v6": "^4.5.11",

Additional Context

No response

@Gbolade-True Gbolade-True added the bug Something isn't working label Jun 27, 2024
@Gbolade-True Gbolade-True changed the title Serialized Error: { code: 'ERR_UNSUPPORTED_DIR_IMPORT' } [BUG] - Serialized Error: { code: 'ERR_UNSUPPORTED_DIR_IMPORT' } Jun 27, 2024
@mimccio
Copy link

mimccio commented Jul 5, 2024

Same issue here

1 similar comment
@gdnthomas
Copy link

Same issue here

@aliemir
Copy link
Member

aliemir commented Jul 30, 2024

Sorry for the issue everyone! This is related with the Material UI's ESM builds and their publishing methods. Check out the issue from Material UI mui/material-ui#30671

We can update all our usage in @refinedev/mui from subpath imports to index imports for @mui/material, @mui/icons-material and @mui/lab which will fix the issue for vitest but previously we had issues with these imports for the bundle size especially in Next.js. We'll investigate if the current state of the bundlers work well to modularize those imports in our package.

Currently, due to issues in Material UI some bundler fail to interpret Material UI imports as ESM. This is not actionable on our side until there are any progress on Material UI side. 🙏

As a workaround for vitest, inlining the @refinedev/mui dep. resolves the errors. Check out below code:

// vite.config.ts
/// <reference types="vitest" />
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  test: {
    environment: "jsdom",
    setupFiles: ["./vitest-setup.js"],
+   server: {
+     deps: {
+       inline: ["@refinedev/mui"]
+     }
+   }
  }
});

We'll update this issue when we have any progress 🙏

@mimccio
Copy link

mimccio commented Jul 30, 2024

Thanks @aliemir for the workaround !

@Gbolade-True
Copy link
Author

Thanks, @aliemir !!
I just implemented the workaround, and it works fine.
Yes, unfortunately, the changes are dependent on Material UI, but hopefully, they fix up soon and a more comprehensive fix can be implemented by the refinedev team.

Great work💯🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants