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

@mui/icons-material:Cannot use import statement outside a module #44860

Closed
iamzwq opened this issue Dec 26, 2024 · 3 comments
Closed

@mui/icons-material:Cannot use import statement outside a module #44860

iamzwq opened this issue Dec 26, 2024 · 3 comments
Assignees
Labels
duplicate This issue or pull request already exists package: icons Specific to @mui/icons

Comments

@iamzwq
Copy link

iamzwq commented Dec 26, 2024

Steps to reproduce

https://stackblitz.com/edit/rr7-demo?file=app%2Froutes%2Fhome.tsx

Current behavior

Error when using mui-icons on a project created with create-react-router
the error message is: Cannot use import statement outside a module

Expected behavior

No response

Context

No response

Your environment

No response

Search keywords: icon, import

@iamzwq iamzwq added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 26, 2024
@aarongarciah aarongarciah added the package: icons Specific to @mui/icons label Dec 26, 2024
@aarongarciah aarongarciah added this to the Material UI v7 (draft) milestone Dec 26, 2024
@aarongarciah
Copy link
Member

@DiegoAndai I assume this will be solved in v7 once we ship ESM improvements (see #43629), but let me know if you know if there's a temporary workaround that can be applied. Using named export like import { AccessAlarm } from '@mui/icons-material' doesn't work either, it throws another error: Unexpected token 'export'.

@DiegoAndai
Copy link
Member

Hey @iamzwq, thanks for the report. In the meantime, you can add ssr.noExternal to your config as such:

import { reactRouter } from '@react-router/dev/vite';
import autoprefixer from 'autoprefixer';
import tailwindcss from 'tailwindcss';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
  },
  plugins: [reactRouter(), tsconfigPaths()],
  ssr: {
    noExternal: ['@mui/icons-material'],
  },
});

This should fix the error.


I'm closing this as a duplicate of #44265

@DiegoAndai DiegoAndai added duplicate This issue or pull request already exists and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 27, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@iamzwq How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists package: icons Specific to @mui/icons
Projects
None yet
Development

No branches or pull requests

3 participants