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

[ESM] Vite + vitest + @mui/material v5.11.0 - createPalette.js:1 seems to be an ES Module but shipped in a CommonJS package. #35773

Open
Tracked by #43938
borgfriend opened this issue Jan 9, 2023 · 7 comments
Assignees
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system

Comments

@borgfriend
Copy link

When using [email protected] and [email protected] with @mui/material.

Starting with "@mui/material": "5.11.0",

I am getting the following error:

Module /<project_name>/node_modules/@mui/material/styles/createPalette.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@mui/material" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    deps: {
      inline: [
        "@mui/material"
      ]
    }
  }
}

Following the advice from the error message does not fix the issue.

For the time being I reverted back to "@mui/material": "5.10.17" - the tests run without any issue.

Any advice on how to use the current version?

@zannager zannager added package: system Specific to @mui/system status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 9, 2023
@mnajdova
Copy link
Member

Are you importing stuff directly from this file? I am asking because that is not supported. We allow imports up to level3, for e.g. @mui/material/styles. All imports which are valid should work as expected. I guess this may be related to #35480

If this is not the case, please share e reproduction repository where we can check the issue.

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 13, 2023
@borgfriend
Copy link
Author

borgfriend commented Jan 17, 2023

We are not importing anything directly from this file.

I am encountering the problem with this repository https://github.com/catenax-ng/product-item-relationship-service-frontend.

@waterbuckit
Copy link

I am experiencing a similar issue when trying to access TablePaginationActions.

I wanted to add a new control to TablePaginationActions , but still maintain current behaviour. TablePaginationActions is imported from @mui/material/TablePagination/TablePaginationActions which, due to being a level4 import is causing the above issue.

Is it possible that we can export TablePaginationActions from @mui/material/TablePagination?

@ldeveber
Copy link

ldeveber commented Feb 17, 2024

I also just received this error with vitest, but I have been trying @mui/material-next with it.

The following change fixed it for me:

// import Chip from "@mui/material-next/Chip";
import Chip from "@mui/material/Chip";

I'm not sure if there are other things that cause this, but I wanted to pass this on in case it helps someone.

EDIT: adding package.json versions:

    "@mui/icons-material": "^5.15.10",
    "@mui/lab": "5.0.0-alpha.165",
    "@mui/material": "^5.15.10",
    "@mui/material-next": "6.0.0-alpha.123",

@Janpot Janpot changed the title Vite + vitest + @mui/material v5.11.0 - createPalette.js:1 seems to be an ES Module but shipped in a CommonJS package. [ESM] Vite + vitest + @mui/material v5.11.0 - createPalette.js:1 seems to be an ES Module but shipped in a CommonJS package. Jul 2, 2024
@sterlingdcs-damian
Copy link

sterlingdcs-damian commented Jul 26, 2024

Is there any workaround for this? Trying to migrate to vite but ran into this.
Spent another day trying to get it working to no avail.. my question on SO if anyone has any insight https://stackoverflow.com/questions/78815858/mui-icons-material-vitest-es-module-issue

@roberbnd
Copy link

@sterlingdcs-damian did you find a solution?

@wilomgfx
Copy link

I'm running in the same issue trying to migrate from Jest to Vitest, any known workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system
Projects
Status: Backlog
Development

No branches or pull requests

10 participants