Reputation: 13
I am building a simple app with the use of webpack to combine all my modules. My webpack seem to be running (although, I have battled its not-working). Now it looks like a bundle.js necessary to see my app cannot be found. I get this error:
So here are my files that might cause the issue
my packageJSON
{
"name": "quiz",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "mocha specs"
},
"author": "",
"license": "ISC",
"devDependencies": {
"mocha": "^3.4.2",
"webpack": "1.12.15"
}
}
and the html file that looks for the bundle.js file
<!DOCTYPE html>
<html>
<head>
<title>Quiz game</title>
</head>
<body>
<script src = "build.js "></script>
<div>
Quiz game
</div>
</body>
</html>
Any ideas on what might be wrong?
Upvotes: 0
Views: 1014
Reputation: 717
First,
Probably, you can change your project structure a little as webpack cli will find the webpack.config.js file under root folder by default.
webpack-demo
|- package.json
+ |- webpack.config.js
|- /dist
|- index.html
|- /src
|- index.js
Second, you may change your webpack.config.js a little bit by require path to point out the output path clearly:
var path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
Third,
If your index.html is under the same folder as bundle.js in dist folder,
<script src="bundle.js"></script>
is correct. But put it at the bottom the body, so that it won't block rendering and can manipulate DOM when page load.
<!DOCTYPE html>
<html>
<head>
<title>Quiz game</title>
</head>
<body>
<div>
Quiz game
</div>
<script src="build.js"></script>
</body>
</html>
Upvotes: 1
Reputation: 141
Your problem is the build.js path to the file.
You're missing just a small part.
Try this: Place a / in your src right before your "build.js"
Upvotes: 0
Reputation: 1
Your problem is that the build.js file cannot be found because the path to the file in the index.html is wrong, it should be should be <script src = "/build.js "></script>
in your index.html not <script src = "build.js "></script>
Upvotes: 0