I play with React (@ 13.3) with babel and webpack.
I have a component that is defined as follows:
import BaseComponent from './BaseComponent'; export default class SomeComponent extends BaseComponent { render() { return ( <div> <img src="http://placekitten.com/g/900/600"/> </div> ); } }
But I get the following error:
Untrained ReferenceError: React not defined
I understand the error: the JSX bit is compiled in React.createElement(...) , but React not in the current scope, since it is not imported.
My questions: What is a clean way around this problem? Do I have to somehow expose React globally with webpack?
Solution Used:
I followed the sentence @ salehen-rahman.
In my webpack.config.js:
module: { loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'react-hot!babel?plugins[]=react-require' }, { test: /\.css$/, loader: 'style!css!autoprefixer?browsers=last 2 versions' }] },
I also needed to fix my tests, so I added this to the helper.js file:
require('babel-core/register')({ ignore: /node_modules/, plugins: ['react-require'], extensions: ['.js'] });
Then my tests are run using the following command:
mocha --require ./test/helper.js 'test/**/*.js'
javascript reactjs webpack babeljs react-jsx
kombucha
source share