Repository: mui/material-ui
File: docs/next.config.ts (TypeScript)

Code before:
          analyzerPort: options.isServer ? 8888 : 8889,
          reportTitle: `${options.isServer ? 'server' : 'client'} docs bundle`,
          // Will be available at `.next/${statsFilename}`
          statsFilename: `stats-${options.isServer ? 'server' : 'client'}.json`,
        }),
      );
    }

    // next includes node_modules in webpack externals. Some of those have dependencies
    // on the aliases defined above. If a module is an external those aliases won't be used.
    // We need tell webpack to not consider those packages as externals.
    if (
      options.isServer &&
      // Next executes this twice on the server with React 18 (once per runtime).
      // We only care about Node runtime at this point.
      (options.nextRuntime === undefined || options.nextRuntime === 'nodejs')
    ) {
      const externals = config.externals.slice(0, -1);
      const nextExternals = config.externals.at(-1);

      config.externals = [
        // @ts-ignore
        (ctx, callback) => {
          const { request } = ctx;
          const hasDependencyOnRepoPackages = [
            'notistack',
            '@mui/x-data-grid',
            '@mui/x-data-grid-pro',
            '@mui/x-data-grid-premium',
            '@mui/x-date-pickers',
            '@mui/x-date-pickers-pro',
            '@mui/x-data-grid-generator',
            '@mui/x-charts',
            '@mui/x-charts-pro',
            '@mui/x-tree-view',
            '@mui/x-tree-view-pro',
            '@mui/x-license',
            '@toolpad/core',
          ].some((dep) => request.startsWith(dep));

          if (hasDependencyOnRepoPackages) {
            return callback(null);
          }
          return nextExternals(ctx, callback);
        },
        ...externals,
      ];
    }

    // @ts-ignore
    config.module.rules.forEach((rule) => {

Review comment (suggestion):


I had claude write a little script to search all dependencies under docs/node_modules and to find any that depend on a workspace package. It came up with this:

```tsx
[
  "@mui-internal/api-docs-builder",
  "@mui/base",
  "@mui/docs",
  "@mui/icons-material",
  "@mui/internal-scripts",
  "@mui/lab",
  "@mui/material",
  "@mui/system",
  "@mui/utils",
  "@mui/x-charts",
  "@mui/x-data-grid",
  "@mui/x-data-grid-generator",
  "@mui/x-data-grid-premium",
  "@mui/x-data-grid-pro",
  "@mui/x-date-pickers",
  "@mui/x-date-pickers-pro",
  "@mui/x-license",
  "@mui/x-tree-view",
  "@toolpad/core",
  "material-ui-popup-state"
]
```

Ignoring the internal ones for a second, interesting to see `notistack` isn't in there and `material-ui-popup-state` is. Verified and it seems to check out.

```suggestion
            'material-ui-popup-state',
```

_edit: We could even automate the initialization of `hasDependencyOnRepoPackages` if we want. The script seems fast enough._

Code after:
          analyzerPort: options.isServer ? 8888 : 8889,
          reportTitle: `${options.isServer ? 'server' : 'client'} docs bundle`,
          // Will be available at `.next/${statsFilename}`
          statsFilename: `stats-${options.isServer ? 'server' : 'client'}.json`,
        }),
      );
    }

    // If a module is an webpack "external" the webpack aliases configured are not used.
    // Next.js includes node_modules in webpack externals, some of those have dependencies
    // on the aliases we defined above.
    // So we need tell webpack to not consider those packages as externals.
    if (
      options.isServer &&
      // Next.js executes this twice on the server with React 18 (once per runtime).
      // We only care about Node runtime at this point.
      (options.nextRuntime === undefined || options.nextRuntime === 'nodejs')
    ) {
      const externals = config.externals.slice(0, -1);
      const nextExternals = config.externals.at(-1);

      config.externals = [
        // @ts-ignore
        (ctx, callback) => {
          const { request } = ctx;
          const hasDependencyOnRepoPackages = [
            'material-ui-popup-state',
            // Assume any X dependencies depend on a package defined in this repository.
            '@mui/x-',
            '@toolpad/core',
          ].some((dep) => request.startsWith(dep));

          if (hasDependencyOnRepoPackages) {
            return callback(null);
          }
          return nextExternals(ctx, callback);
        },
        ...externals,
      ];
    }

    // @ts-ignore
    config.module.rules.forEach((rule) => {
      rule.resourceQuery = { not: [/raw/] };
    });

    return {
      ...config,
      plugins,
      resolve: {
        ...config.resolve,