I got this unusual error after webpack installation, Searched whole web tried all solution but nothing works,
//My webpack.config.js file
const webpack = require("webpack");
const path = require("path");
const config = {
entry : path.resolve(__dirname,"src/index.js"),
output : {
path : path.resolve(__dirname,"dist/assets"),
filename : "bundle.js",
publicPath : "assets"
},
devServer : {
inline : true,
contentBase : path.resolve(__dirname,"dist"),
port : 3000
},
module : {
rules : [
{
test : /\.js$/,
exclude : path.resolve(__dirname,"node_modules"),
loader : "babel-loader",
query: {
presets: ["env","latest","react","stage-0","es2015"]
}
},
{
test : /\.css$/,
loader: 'style-loader!css-loader!autoprefixer-loader'
},
{
test : /\.scss$/,
loader: 'style-loader!css-loader!autoprefixer-loader!sass-loader'
}
]
}
};
module.exports = config;
My babelrc file
{
"presets" : ["env","latest","react","stage-0","es2015"]
}
Index.js file
import React from 'react'
import ReactDOM from 'react-dom'
import { hello, goodbye } from './lib'
ReactDOM.render(
<div>
{hello}
{goodbye}
</div>,
document.getElementById('root')
);
lib.js file
import React from 'react'
import text from './titles.json'
import './stylesheets/hello.css'
import './stylesheets/goodbye.scss'
export const hello = (
<h1 id="title"
className="hello">
{text.hello}
</h1>
);
export const goodbye = (
<h2 id="goodbye"
className="goodbye">
{text.bye}
</h2>
);
titles.json
{
"hello" : "Bonjour",
"bye" : "Au Revoir"
}
i didnot include json loader in webpack.config file as i found out that json loader is added in webpack by default and when i check in browser in console i get this error -> ReferenceError: ReactDOM is not defined.
Error that i get in CLI
//Folder Structure