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

Remove Material UI import babel transformation #322

Merged
merged 6 commits into from
Nov 15, 2021

Conversation

codemonkey800
Copy link
Collaborator

@codemonkey800 codemonkey800 commented Nov 15, 2021

Description

This removes the buggy babel transformation for Material UI imports. We originally used this so that we could improve build performance while using root imports like import { Accordion, Button } from '@material-ui/core'. However, this has proven to be very buggy (and occasionally blocking) for developers due to intermittent errors related to default exports:

/home/runner/work/example-plugin/example-plugin/napari-hub/frontend/node_modules/@material-ui/styles/esm/ServerStyleSheets/index.js:1
export { default } from './ServerStyleSheets';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.4309 (/home/runner/work/example-plugin/example-plugin/napari-hub/frontend/.next/server/pages/_document.js:20:43)
    at __webpack_require__ (/home/runner/work/example-plugin/example-plugin/napari-hub/frontend/.next/server/webpack-runtime.js:25:42) {
  type: 'SyntaxError'
}

With no clear solution in sight, and with Next.js removing babel in the v12 release, this PR refactors the imports to import from the module directly instead of from the root import.

This also adds an eslint plugin that verifies that root imports aren't being used in the app, so using the following imports will now throw an eslint error:

import { Button } from '@material-ui/core';
import { Add } from '@material-ui/icons';
import { CSSProperties } from '@material-ui/styles';

Demo

image

Copy link
Contributor

@DragaDoncila DragaDoncila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, love the eslint rule!

@codemonkey800 codemonkey800 merged commit 3d72237 into main Nov 15, 2021
@codemonkey800 codemonkey800 deleted the jeremy/remove-mui-babel-plugin branch November 15, 2021 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants