Broken styles when using Material UI with babel and the 'with styles' feature

We've implemented babel and lerna to maintain specific elements of our react web app separately. While the setup has been effective thus far, we're encountering styling issues when generating the static build.

The main project is not processed through babel and has no connection to it.

The components that are separated have these babel dependencies:

"devDependencies": {
    "@babel/cli": "^7.2.0",
    "@babel/core": "^7.2.0",
    "@babel/plugin-proposal-class-properties": "^7.2.1",
    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-env": "^7.2.0",
    "@babel/preset-react": "^7.0.0"
  },
  "dependencies": {
    "@babel/runtime": "^7.2.0",
    ...
  }

Here's our configuration file:

module.exports = {
    plugins: [
        ['@babel/plugin-proposal-class-properties', { loose: true }],
        '@babel/plugin-transform-runtime'
    ],
    presets: [
        '@babel/preset-env',
        '@babel/preset-react'
    ]
};

To create our 'babelised' package, we use the command

./node_modules/.bin/babel ./src/ -d ./dist/ --copy-files
, which we then link to the core app using lerna.

For most of our components, we utilize material-ui and apply inline CSS using the syntax withStyles(style)(Component).

While everything functions as expected with npm start in the core project, the styling breaks in the 'babelised' component after building with npm run-script build.

Has anyone else faced this issue or have insight into why it's happening?

UPDATE:

As requested, here's a snippet of the styles used in the react app:

[styles code goes here]

We implement the Material-UI withStyles higher order component like this:

export default withStyles(styles)(MyClass);

After running it through babel, we get something similar to:

[babel output code goes here]

And:

var _default = (0, _withStyles.default)(styles)(MyClass);

The import for _withStyles looks like this:

var _withStyles = _interopRequireDefault(require("@material-ui/core/styles/withStyles"));

There are no error messages but the layout becomes completely unusable due to the loss of styling.

Answer №1

Consider including the following plugin in your .babelrc file:

["@babel/plugin-proposal-decorators", {"legacy": true}],

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

switching the color of a path in an SVG when hovering over a

In the midst of working on SVG, I'm trying to implement a color change effect upon hover. The desired functionality is such that when hovering over the .business div, the color of the SVG business path should also change accordingly as specified in th ...

varied reactions between componentDidMount and useEffect when employing jquery emoji plugin

Currently, I am facing an issue with a jquery emoji plugin that I need to use on one of my components until I complete building a custom plugin. Interestingly, when I call the emoji plugin inside componentDidMount, everything works fine, except for the ab ...

Displaying localized error messages in React

Currently, I am developing a FrontEnd application using React and implementing L10n for localization. The process works smoothly for displaying static text like this: <input {...input} type="password" placeholder={strings.passwordPlaceholder} ...

Show only half of the Google Charts

I have a code snippet that displays a chart with dimensions of 500x500. However, I only want to show half of the chart, like 500x250. But whenever I adjust the values in the div, it resizes the entire chart instead of just showing half. My goal is to hide ...

What is the appropriate way to retrieve an array that has been stored in the this.state property?

https://i.stack.imgur.com/y9huN.jpgAs a newcomer to react, I have been exploring the react documentation on making Ajax calls. While the docs make it seem simple to retrieve JSON information and set it to a state variable, I've encountered some challe ...

Exporting modules from React and Jest using the spyOn function

setupTests.ts: jest.mock('hooks', () => ({ useCurrentUser: () => mockOwner, })); component.test.ts: import * as hooks from 'hooks'; test('delete organization', async () => { const spy = jest.spyOn(hooks, &apos ...

Exploring the Power of JQuery with Hover Effects and SlideToggle

I was struggling to keep the navbar displaying without it continuously toggling when my pointer hovered over it. I just wanted it to stay visible until I moved my pointer away. <script> $(document).ready(function(){ $(".menu-trigger").hover(funct ...

Error: Unable to access the "then" function on JSON.stringify()

I am encountering an issue as a newcomer to React. My objective is to add departments to a table using the web API that I developed in Visual Studio. The plan is to utilize a modal popup to facilitate adding the department. However, I have hit a roadblock. ...

Referencing other styled-components in Typescript and React code bases

I'm attempting to replicate this code snippet found on https://styled-components.com/docs/advanced using TypeScript. const Link = styled.a` display: flex; align-items: center; padding: 5px 10px; background: papayawhip; color: palevioletred; ...

After clicking multiple times within the modal, the modal popup begins to shift towards the left side

I successfully implemented a modal popup in my project, but encountered an issue where the popup moves to the left side if clicked multiple times. Despite searching extensively online, I have not been able to find a solution to this problem. Below is the ...

How to selectively import specific modules in three.js using ES6 syntax

I recently integrated the three.js library using NPM with the goal of leveraging its new ES6 modular architecture. This design allows for selective importation of specific modules as outlined in this resource: Threejs - Import via modules. For bundling an ...

How would the input value change if the clock time changed?

I am working with dynamic inputs that allow me to add and delete rows with inputs. These inputs include material-ui timepickers, which have an icon of a clock next to the input field. When I click on the clock icon, a clock widget appears. However, the val ...

Updating a property in React by fetching data from API and storing it in the cache

Recently, I implemented nanoid to generate unique IDs for my NBA team stat tracker app. However, upon browser refresh, the fetch function generates new IDs for each team stored in the favorites list. This causes the app to fetch data again and assign a new ...

Unable to resize static and draggable elements simultaneously

Observe this fiddle to see the demonstration: DEMO If you are interested in the resizing of white divs, check out this link: Resizing of White divs The draggable divs are represented by red while the static divs are shown in white and located in droppabl ...

HTML5 Video Frozen in Place on Screen's Edge

I am encountering a problem specifically on Webkit, particularly in web view on iOS. When I tested it on desktop Chrome, the issue did not appear. Here is the Portrait image and Here is the Landscape image The video seems to be fixed in one position rega ...

What are the steps for implementing Kotlin + React + Redux with create-react-kotlin-app?

I am currently utilizing the create-react-kotlin-app tool and following the step-by-step guide available on its official GitHub repository, in order to develop a React + Redux application using Kotlin. The initial installation steps proceeded smoothly: cr ...

Develop your website layout with Flexbox (Bootstrap 4.2), using stacked grid designs similar to the float: left method

For my Wordpress theme, I am utilizing Bootstrap 4.2 to design a basic grid layout for a list of blog posts. In my design, I have a Card that is double the height of others and I am attempting to 'float' two single-height cards beside it. Previ ...

Exploring the Children Property in TypeScript and the Latest Version of React

Within my App.tsx file, I am passing <Left /> and <Right /> as components to an imported component named <SplitScreen />. It seems that in React 18, the "children" prop needs to be explicitly typed. When I type it as React.Element[], eve ...

Invalid Value Provided for CSS Clip Path

I'm currently attempting to design a sophisticated clip-path using a logo in CSS, but I keep receiving an error stating "Invalid Property Value." The X and Y coordinates have been computed based on dimensions of 508px x 190px https://i.sstatic.net/Yh ...

Having a slight hiccup with pixel alignment and browser compatibility in my jQuery animation

To emphasize a specific paragraph element, I developed a JavaScript function that displays it above a darkened background. My approach involved using jQuery to generate an overlay and then duplicating the targeted paragraph element while positioning it ab ...