Skip to content

Babel-plugin-import plugin results in every component returning undefined #45913

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

Open
anthonyma94 opened this issue Apr 14, 2025 · 0 comments
Open
Assignees
Labels
package: material-ui Specific to @mui/material status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@anthonyma94
Copy link

anthonyma94 commented Apr 14, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/github-rga63amd?file=vite.config.ts
  2. Let it run.

Current behavior

Following the docs here, I tried setting up bundle minimizing. However, every component becomes undefined.

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          [
            'babel-plugin-import',
            {
              libraryName: '@mui/material',
              libraryDirectory: '',
              camel2DashComponentName: false,
            },
            'core',
          ],
          [
            'babel-plugin-import',
            {
              libraryName: '@mui/icons-material',
              libraryDirectory: '',
              camel2DashComponentName: false,
            },
            'icons',
          ],
        ],
      },
    }),
  ],
});

Uncaught ReferenceError: CssBaseline is not defined and so on.

Tested on v7.0.2, on both Firefox and Chrome.

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: babel, bundle, vite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants