Uncaught ReferenceError: React is not defined

前端 未结 12 1872
予麋鹿
予麋鹿 2020-11-30 02:17

I am trying to make ReactJS work with rails using this tutorial. I am getting this error:


Uncaught ReferenceError: React is not defined

12条回答
  •  伪装坚强ぢ
    2020-11-30 02:58

    I was able to reproduce this error when I was using webpack to build my javascript with the following chunk in my webpack.config.json:

    externals: {
        'react': 'React'
    },
    

    This above configuration tells webpack to not resolve require('react') by loading an npm module, but instead to expect a global variable (i.e. on the window object) called React. The solution is to either remove this piece of configuration (so React will be bundled with your javascript) or load the React framework externally before this file is executed (so that window.React exists).

提交回复
热议问题