Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'attach' of undefined makeStyles.js

When trying to access the Login component of my MERN app on the production version, I get a series of the following type errors shown in this image:

enter image description here

My app (https://github.com/ahaq0/kumon_schedule) works perfectly fine locally and was working perfectly fine hosted on Heroku earlier today.

I tried rolling back all of the changes in the code that I made today to no avail. Similarly, I checked the package.json (and .lock) to see if I changed the material UI dependency but that was the same. I can't seem to figure out why it stopped working all of a sudden on the hosted version here.

The code for the line of the error is below. However, I did not write as it's a part of material UI.

if (sheetManager.dynamicStyles) {
    var dynamicSheet = stylesOptions.jss.createStyleSheet(sheetManager.dynamicStyles, _extends({
        link: true
    }, options));
    dynamicSheet.update(props).attach();
    state.dynamicSheet = dynamicSheet;
    state.classes = mergeClasses({
        baseClasses: sheetManager.staticSheet.classes,
        newClasses: dynamicSheet.classes
    });

    if (sheetsRegistry) {
        sheetsRegistry.add(dynamicSheet);
    }
} else {
    state.classes = sheetManager.staticSheet.classes;
}

sheetManager.refs += 1;

This is my first deployed app and I'm at a loss how everything went from working to not working despite my best attempts to roll things back.

Edit. I should mention I tested in Firefox as well as Chrome where the error log is from.

Edit #2. After a lot more debugging I found out that the error is gone if I roll back to commit fccc55a5 via Heroku. However, if I make a new branch with that commit and try to deploy that branch, it will not work.

Please see here https://github.com/ahaq0/kumon_schedule/compare/fccc55a5...fccc55a5

When I revert to that last build in Heroku it will work. But if I merge that previous commit into a new branch and try to deploy it, it will not.

like image 667
Indistinct Avatar asked Dec 28 '19 04:12

Indistinct


4 Answers

Adding "jss": "10.0.0" to "dependencies": { } fixed the issue for me

--- Updated 30.12.19 ---

"jss" can now be removed,

bug has been fixed in:

"@material-ui/core": "4.8.2",
like image 146
jouta helm Avatar answered Nov 06 '22 01:11

jouta helm


If you're using yarn like me, then you can solve it by adding a resolutions field to your package.json targeting jss 10.0.0 version.

package.json should look like this:

{

  "dependencies": {
    "@material-ui/core": "^4.8.1",

  },
  "resolutions": {
    "jss": "10.0.0"
  }
}

I shared my solution on Github too (and seems it worked for others): https://github.com/mui-org/material-ui/issues/19005#issuecomment-569447204

Please accept the answer if it also worked for you too! :)

like image 6
Alfonso M. García Astorga Avatar answered Nov 05 '22 23:11

Alfonso M. García Astorga


In my case it was resolved by removing the Box component.

like image 3
unknown Avatar answered Nov 05 '22 23:11

unknown


I am facing the same issue. It occured because I updated @material-ui/core^4.4.0 to @material-ui/core^4.8.1. There maybe breaking changes in the new version or a bug. The latest version has released just four days ago so there might not be a solution yet. But for your problem try downgrading to @material-ui/core^4.4.0 or the previous version of material-ui you were using, it should work. There is no need to rollback to previous commits.

like image 1
Lalit Jharbade Avatar answered Nov 05 '22 23:11

Lalit Jharbade