How to serve React app with Material-UI and react-router










5















I developed an application with this major components React + Material-UI + react-router. Here is my full package.json:




"name": "trader-ui",
"version": "0.1.0",
"private": true,
"dependencies":
"@material-ui/core": "^3.2.0",
"@material-ui/icons": "^3.0.1",
"@stomp/stompjs": "^5.0.0",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.4"
,
"scripts":
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
,
"eslintConfig":
"extends": "react-app"
,
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://localhost:8080"



It works just fine on the development server:



$ npm start


Here it is:



enter image description here



However, when I tried to serve a production build:



$ npm run build
$ npm install -g serve
$ serve -s build


It looks:



enter image description here



Could somebody tell me what went wrong with the production build?










share|improve this question






















  • Do you see any errors if you check the Network tab of your Developer Tools?

    – Tholle
    Nov 15 '18 at 10:47






  • 1





    check if this helps: material-ui.com/getting-started/faq/…

    – giorgim
    Nov 15 '18 at 10:51












  • @Tholle, no errors

    – Alex Karasev
    Nov 15 '18 at 13:24















5















I developed an application with this major components React + Material-UI + react-router. Here is my full package.json:




"name": "trader-ui",
"version": "0.1.0",
"private": true,
"dependencies":
"@material-ui/core": "^3.2.0",
"@material-ui/icons": "^3.0.1",
"@stomp/stompjs": "^5.0.0",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.4"
,
"scripts":
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
,
"eslintConfig":
"extends": "react-app"
,
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://localhost:8080"



It works just fine on the development server:



$ npm start


Here it is:



enter image description here



However, when I tried to serve a production build:



$ npm run build
$ npm install -g serve
$ serve -s build


It looks:



enter image description here



Could somebody tell me what went wrong with the production build?










share|improve this question






















  • Do you see any errors if you check the Network tab of your Developer Tools?

    – Tholle
    Nov 15 '18 at 10:47






  • 1





    check if this helps: material-ui.com/getting-started/faq/…

    – giorgim
    Nov 15 '18 at 10:51












  • @Tholle, no errors

    – Alex Karasev
    Nov 15 '18 at 13:24













5












5








5








I developed an application with this major components React + Material-UI + react-router. Here is my full package.json:




"name": "trader-ui",
"version": "0.1.0",
"private": true,
"dependencies":
"@material-ui/core": "^3.2.0",
"@material-ui/icons": "^3.0.1",
"@stomp/stompjs": "^5.0.0",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.4"
,
"scripts":
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
,
"eslintConfig":
"extends": "react-app"
,
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://localhost:8080"



It works just fine on the development server:



$ npm start


Here it is:



enter image description here



However, when I tried to serve a production build:



$ npm run build
$ npm install -g serve
$ serve -s build


It looks:



enter image description here



Could somebody tell me what went wrong with the production build?










share|improve this question














I developed an application with this major components React + Material-UI + react-router. Here is my full package.json:




"name": "trader-ui",
"version": "0.1.0",
"private": true,
"dependencies":
"@material-ui/core": "^3.2.0",
"@material-ui/icons": "^3.0.1",
"@stomp/stompjs": "^5.0.0",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.4"
,
"scripts":
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
,
"eslintConfig":
"extends": "react-app"
,
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://localhost:8080"



It works just fine on the development server:



$ npm start


Here it is:



enter image description here



However, when I tried to serve a production build:



$ npm run build
$ npm install -g serve
$ serve -s build


It looks:



enter image description here



Could somebody tell me what went wrong with the production build?







javascript reactjs react-router material-ui






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 10:41









Alex KarasevAlex Karasev

405415




405415












  • Do you see any errors if you check the Network tab of your Developer Tools?

    – Tholle
    Nov 15 '18 at 10:47






  • 1





    check if this helps: material-ui.com/getting-started/faq/…

    – giorgim
    Nov 15 '18 at 10:51












  • @Tholle, no errors

    – Alex Karasev
    Nov 15 '18 at 13:24

















  • Do you see any errors if you check the Network tab of your Developer Tools?

    – Tholle
    Nov 15 '18 at 10:47






  • 1





    check if this helps: material-ui.com/getting-started/faq/…

    – giorgim
    Nov 15 '18 at 10:51












  • @Tholle, no errors

    – Alex Karasev
    Nov 15 '18 at 13:24
















Do you see any errors if you check the Network tab of your Developer Tools?

– Tholle
Nov 15 '18 at 10:47





Do you see any errors if you check the Network tab of your Developer Tools?

– Tholle
Nov 15 '18 at 10:47




1




1





check if this helps: material-ui.com/getting-started/faq/…

– giorgim
Nov 15 '18 at 10:51






check if this helps: material-ui.com/getting-started/faq/…

– giorgim
Nov 15 '18 at 10:51














@Tholle, no errors

– Alex Karasev
Nov 15 '18 at 13:24





@Tholle, no errors

– Alex Karasev
Nov 15 '18 at 13:24












1 Answer
1






active

oldest

votes


















0














Thanks to @giorgim for his suggestion. It was correct. Use Material-UI FAQ to resolve the issue:




https://material-ui.com/getting-started/faq/#why-aren--39-t-my-components-rendering-correctly-in-production-builds-




My code for styles setup was in withRoot.js:



import React from 'react';
import createMuiTheme, MuiThemeProvider from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';

const theme = createMuiTheme(
typography:
useNextVariants: true,
,
);

function withRoot(Component)
function WithRoot(props)
return (
<MuiThemeProvider theme=theme>
<CssBaseline />
<Component ...props />
</MuiThemeProvider>
);


return WithRoot;


export default withRoot;


I simply wrapped my components with JssProvider:



import React from 'react';
import create from 'jss';
import JssProvider from 'react-jss/lib/JssProvider';
import
MuiThemeProvider,
createMuiTheme,
createGenerateClassName,
jssPreset,
from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';

const theme = createMuiTheme(
typography:
useNextVariants: true,
,
);

const jss = create(jssPreset());
const generateClassName = createGenerateClassName();

function withRoot(Component)
function WithRoot(props)
return (
<JssProvider jss=jss generateClassName=generateClassName>
<MuiThemeProvider theme=theme>
<CssBaseline />
<Component ...props />
</MuiThemeProvider>
</JssProvider>
);


return WithRoot;


export default withRoot;


Of course you should install react-jss beforehand:



$ npm install react-jss





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317591%2fhow-to-serve-react-app-with-material-ui-and-react-router%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Thanks to @giorgim for his suggestion. It was correct. Use Material-UI FAQ to resolve the issue:




    https://material-ui.com/getting-started/faq/#why-aren--39-t-my-components-rendering-correctly-in-production-builds-




    My code for styles setup was in withRoot.js:



    import React from 'react';
    import createMuiTheme, MuiThemeProvider from '@material-ui/core/styles';
    import CssBaseline from '@material-ui/core/CssBaseline';

    const theme = createMuiTheme(
    typography:
    useNextVariants: true,
    ,
    );

    function withRoot(Component)
    function WithRoot(props)
    return (
    <MuiThemeProvider theme=theme>
    <CssBaseline />
    <Component ...props />
    </MuiThemeProvider>
    );


    return WithRoot;


    export default withRoot;


    I simply wrapped my components with JssProvider:



    import React from 'react';
    import create from 'jss';
    import JssProvider from 'react-jss/lib/JssProvider';
    import
    MuiThemeProvider,
    createMuiTheme,
    createGenerateClassName,
    jssPreset,
    from '@material-ui/core/styles';
    import CssBaseline from '@material-ui/core/CssBaseline';

    const theme = createMuiTheme(
    typography:
    useNextVariants: true,
    ,
    );

    const jss = create(jssPreset());
    const generateClassName = createGenerateClassName();

    function withRoot(Component)
    function WithRoot(props)
    return (
    <JssProvider jss=jss generateClassName=generateClassName>
    <MuiThemeProvider theme=theme>
    <CssBaseline />
    <Component ...props />
    </MuiThemeProvider>
    </JssProvider>
    );


    return WithRoot;


    export default withRoot;


    Of course you should install react-jss beforehand:



    $ npm install react-jss





    share|improve this answer



























      0














      Thanks to @giorgim for his suggestion. It was correct. Use Material-UI FAQ to resolve the issue:




      https://material-ui.com/getting-started/faq/#why-aren--39-t-my-components-rendering-correctly-in-production-builds-




      My code for styles setup was in withRoot.js:



      import React from 'react';
      import createMuiTheme, MuiThemeProvider from '@material-ui/core/styles';
      import CssBaseline from '@material-ui/core/CssBaseline';

      const theme = createMuiTheme(
      typography:
      useNextVariants: true,
      ,
      );

      function withRoot(Component)
      function WithRoot(props)
      return (
      <MuiThemeProvider theme=theme>
      <CssBaseline />
      <Component ...props />
      </MuiThemeProvider>
      );


      return WithRoot;


      export default withRoot;


      I simply wrapped my components with JssProvider:



      import React from 'react';
      import create from 'jss';
      import JssProvider from 'react-jss/lib/JssProvider';
      import
      MuiThemeProvider,
      createMuiTheme,
      createGenerateClassName,
      jssPreset,
      from '@material-ui/core/styles';
      import CssBaseline from '@material-ui/core/CssBaseline';

      const theme = createMuiTheme(
      typography:
      useNextVariants: true,
      ,
      );

      const jss = create(jssPreset());
      const generateClassName = createGenerateClassName();

      function withRoot(Component)
      function WithRoot(props)
      return (
      <JssProvider jss=jss generateClassName=generateClassName>
      <MuiThemeProvider theme=theme>
      <CssBaseline />
      <Component ...props />
      </MuiThemeProvider>
      </JssProvider>
      );


      return WithRoot;


      export default withRoot;


      Of course you should install react-jss beforehand:



      $ npm install react-jss





      share|improve this answer

























        0












        0








        0







        Thanks to @giorgim for his suggestion. It was correct. Use Material-UI FAQ to resolve the issue:




        https://material-ui.com/getting-started/faq/#why-aren--39-t-my-components-rendering-correctly-in-production-builds-




        My code for styles setup was in withRoot.js:



        import React from 'react';
        import createMuiTheme, MuiThemeProvider from '@material-ui/core/styles';
        import CssBaseline from '@material-ui/core/CssBaseline';

        const theme = createMuiTheme(
        typography:
        useNextVariants: true,
        ,
        );

        function withRoot(Component)
        function WithRoot(props)
        return (
        <MuiThemeProvider theme=theme>
        <CssBaseline />
        <Component ...props />
        </MuiThemeProvider>
        );


        return WithRoot;


        export default withRoot;


        I simply wrapped my components with JssProvider:



        import React from 'react';
        import create from 'jss';
        import JssProvider from 'react-jss/lib/JssProvider';
        import
        MuiThemeProvider,
        createMuiTheme,
        createGenerateClassName,
        jssPreset,
        from '@material-ui/core/styles';
        import CssBaseline from '@material-ui/core/CssBaseline';

        const theme = createMuiTheme(
        typography:
        useNextVariants: true,
        ,
        );

        const jss = create(jssPreset());
        const generateClassName = createGenerateClassName();

        function withRoot(Component)
        function WithRoot(props)
        return (
        <JssProvider jss=jss generateClassName=generateClassName>
        <MuiThemeProvider theme=theme>
        <CssBaseline />
        <Component ...props />
        </MuiThemeProvider>
        </JssProvider>
        );


        return WithRoot;


        export default withRoot;


        Of course you should install react-jss beforehand:



        $ npm install react-jss





        share|improve this answer













        Thanks to @giorgim for his suggestion. It was correct. Use Material-UI FAQ to resolve the issue:




        https://material-ui.com/getting-started/faq/#why-aren--39-t-my-components-rendering-correctly-in-production-builds-




        My code for styles setup was in withRoot.js:



        import React from 'react';
        import createMuiTheme, MuiThemeProvider from '@material-ui/core/styles';
        import CssBaseline from '@material-ui/core/CssBaseline';

        const theme = createMuiTheme(
        typography:
        useNextVariants: true,
        ,
        );

        function withRoot(Component)
        function WithRoot(props)
        return (
        <MuiThemeProvider theme=theme>
        <CssBaseline />
        <Component ...props />
        </MuiThemeProvider>
        );


        return WithRoot;


        export default withRoot;


        I simply wrapped my components with JssProvider:



        import React from 'react';
        import create from 'jss';
        import JssProvider from 'react-jss/lib/JssProvider';
        import
        MuiThemeProvider,
        createMuiTheme,
        createGenerateClassName,
        jssPreset,
        from '@material-ui/core/styles';
        import CssBaseline from '@material-ui/core/CssBaseline';

        const theme = createMuiTheme(
        typography:
        useNextVariants: true,
        ,
        );

        const jss = create(jssPreset());
        const generateClassName = createGenerateClassName();

        function withRoot(Component)
        function WithRoot(props)
        return (
        <JssProvider jss=jss generateClassName=generateClassName>
        <MuiThemeProvider theme=theme>
        <CssBaseline />
        <Component ...props />
        </MuiThemeProvider>
        </JssProvider>
        );


        return WithRoot;


        export default withRoot;


        Of course you should install react-jss beforehand:



        $ npm install react-jss






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 8:29









        Alex KarasevAlex Karasev

        405415




        405415





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317591%2fhow-to-serve-react-app-with-material-ui-and-react-router%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3