I have been following the react setup instructions on codecademy:
When I type in “npm run build” into the terminal I get this error:
I can’t seem to figure out how to get it to work.
Here is the link to my code on my github: https://github.com/throwkill999/react_demo
Advertisement
Answer
The error tells you that output.build
is not a valid option. You probably meant to use output.path
. There are other problems with how you concatenate __dirname
in some places, because you need a leading /
for them. But it’s better to use path.resolve
for that.
Your config would look like this:
JavaScript
x
26
26
1
var path = require('path');
2
var HTMLWebpackPlugin = require('html-webpack-plugin');
3
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
4
template: path.resolve(__dirname, 'app/index.html'),
5
filename: 'index.html',
6
inject: 'body'
7
});
8
9
module.exports = {
10
entry: path.resolve(__dirname, 'app/index.js'),
11
module: {
12
loaders: [
13
{
14
test: /.js$/,
15
exclude: /node_modules/,
16
loader: 'babel-loader'
17
}
18
]
19
},
20
output: {
21
filename: 'transformed.js',
22
path: path.resolve(__dirname, 'build')
23
},
24
plugins: [HTMLWebpackPluginConfig]
25
};
26
Also in ./app/index.js
you have a typo, it should be ./components/Apps
(you forgot the s
).