0

I am able to transpile the jsx code but in browser its not loading anything. I am using babel and webpack too.

app.jsx

const ReactDom = require('react-dom');
const React = require('react');
ReactDOM.render(
    <h1>Hello World</h1>,
    document.getElementById("root")
);

index.html

<html>
    <head>

    </head>
    <body>
        <div id="root"></div>
        <script type="text/javascript" src="./js/bundle.js">
        </script>
    </body>
</html>

webpack.config.js

module.exports = {
    entry: './jsx/app.jsx',
    output: {
        path: __dirname + '/js/',
        filename: 'bundle.js'
    },

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules)/,
                loaders: ['babel-loader']
            }
        ]
    }
}

bundle.js

------
------

(function(module, exports, __webpack_require__) {

const ReactDom = __webpack_require__(15);
const React = __webpack_require__(4);
ReactDOM.render(React.createElement(
    'h1',
    { htmlFor: 'yes' },
    'Hello World'
), document.getElementById("root"));

}),

------
------

When I looked into html page source it showing linked to bundle.js in script tag but page is blank. You can check my complete project on Github complete code

Steps I am following to run

npm run build static (I am using node-static)

then loading index.html in browser but page is blank.

1
  • Any errors in your browser console? Without seeing your directory structure I suspect it might be a pathing issue Commented Jan 17, 2018 at 3:52

1 Answer 1

3

You have a typo - ReactDOM should be ReactDom. The error that is shown in the console is Uncaught ReferenceError: ReactDOM is not defined.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.