Krishna Krishna - 7 days ago 5
Javascript Question

Webpack bundled file not generated

I am just new to webpack and react , just going through the docs and created a example to work. Unfortunately i got stuck and not able to proceed . Th problem is the bundled file is not generated.
The files i created is

package.json

{
"name": "rohith",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.4.1",
"react-dom": "^15.4.1",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
}
}


webpack.config.js

module.export = {
entry : './main.js',
output : {
path : './',
filename : 'index.js'
},
devServer : {
inline : true,
port : 3333
},
module : {
loaders : [
{
test : /\.js$/,
exclude : /node_modules/,
loader : 'babel',
query : {
presets : ['es2015','react']
}
}
]
}
}


App.js

import React from 'react';
class App extends React.Component {
render(){
return <div>Hello</div>
}
}

export default App


main.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />,document.getElementById('app'));


index.html

<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>Setup</title>
</head>
<body>
<div id = "app"></div>
<script src ="index.js"></script>
</body>
</html>


I am getting that bundle is valid, but no index.js is generated.
can't run in localhost 3333

Thanks,

Answer

In webpack.config.js, use module.exports instead of module.export. See Output filename not configured Error in Webpack Also be noticed that your package.json lacks some dependencies. Here is the updated package.json that works:

{
"name": "rohith",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
  "react": "^15.4.1",
  "react-dom": "^15.4.1",
  "webpack": "^1.13.3",
  "webpack-dev-server": "^1.16.2"
},
"devDependencies": {
  "babel": "^6.5.2",
  "babel-core": "^6.18.2",
  "babel-loader": "^6.2.8",
  "babel-preset-es2015": "^6.18.0",
  "babel-preset-react": "^6.16.0"
}
}
Comments