Skip to content

Webpack-dev-server serves a directory list instead of the app page #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
acircuit opened this issue Jul 26, 2016 · 11 comments
Closed

Webpack-dev-server serves a directory list instead of the app page #538

acircuit opened this issue Jul 26, 2016 · 11 comments
Labels

Comments

@acircuit
Copy link

screenshot from 2016-07-26 15 55 14
My Web app config :
`var webpack = require('webpack');
var path = require('path');

module.exports = {
entry: [
'webpack-dev-server/client?http://127.0.0.1:8080',
'webpack/hot/only-dev-server',
'./src/index.jsx'
],
output: {
path: path.join(__dirname,'public'),
filename: 'bundle.js',
publicPath: 'http://localhost:8080'
},
devServer: {
contentBase: "./public",
hot: true
},
resolve: {
modulesDirectories: ['node_modules','src'],
extensions: ['','.js']
},
module: {
loaders: [
{
test: /.jsx?$/,
exclude: /node_modules/,
loaders: ['react-hot','babel?presets[]=react,presets[]=react,presets[]=es2015']
}

    ]
},
plugins:[
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
]

};
`
This is my directory structure :
screenshot from 2016-07-26 15 57 09

Please help me with this as i am not able to see my index.html. Is there something wrong with my config file

@Jack-Barry
Copy link

Jack-Barry commented Aug 4, 2016

Have you tried running it without the contentBase: "./public"? It looks like it might be pointing to your public directory when you pull it up in the browser. You might also try moving the index.html into the public directory temporarily to see if it loads as you're expecting to see if that's what's happening.

@KevinHoughton
Copy link

I'm getting the same view.

// Dev server
config.devServer = {
    contentBase: '/',
    proxy: {
        // @see: https://github.com/nodejitsu/node-http-proxy#options
        '*': {
            target: 'http://localhost:8000'
        }
    },
    host: '0.0.0.0',
    port: process.env.WEBPACK_PORT || '8080',
    // Serve webpack-dev-server over HTTPS Protocol.
    // Includes a self-signed certificate that is used when serving the requests.
    https: false
};

@SpaceK33z
Copy link
Member

@KevinHoughton, you'll get that if there is no index.html in the directory to which you point contentBase. Can you try including the absolute path to the directory that has a index.html?

@yvbeek
Copy link

yvbeek commented Sep 6, 2016

I am having the same problem in the latest version. The contentBase property seems to be ignored. Both relative and absolute path are not working.

In my webpack.config.js (this worked fine before the update):

const CONFIG = {
  bundleDir: path.join(__dirname, 'bundle'),
  mainIndex: 'index.html',
  serverHost: '0.0.0.0',
  serverPort: 8000
}

...

devServer: {
    host: CONFIG.serverHost,
    port: CONFIG.serverPort,
    open: CONFIG.mainIndex,
    contentBase: CONFIG.bundleDir,
    colors: true
}

Now it only works when I specify the contentBase as a command line argument:

"scripts": {
  "server": "webpack-dev-server --content-base bundle",
}

@SpaceK33z
Copy link
Member

@ZyphraX, this was a bug in the latest beta and has been fixed with #597.

@SpaceK33z
Copy link
Member

I'm closing this issue because of inactivity. Feel free to comment, and we can always re-open it again.

@ajkhatibi
Copy link

I have a very similar problem. Is this an issue with webpack?

@alexlevy0
Copy link

Same issue as well

@shellscape
Copy link
Contributor

@alexlevy0 please avoid posting "same" or "me too" comments on a thread. Rather, use the reaction button an add a thumbs-up reaction to the OP or another comment. See here for more information on reactions.

@abh4chat
Copy link

abh4chat commented Dec 7, 2017

SpaceK33z answer was solution, when i faced similar problem, which got introduced with file structure reorganization, i moved everything under a src folder which was outside. I moved index.html outside and that worked. Alternative solution use html-webpack-plugin.

@JuxhinB
Copy link

JuxhinB commented Oct 19, 2020

I am having the same problem in the latest version. The contentBase property seems to be ignored. Both relative and absolute path are not working.

In my webpack.config.js (this worked fine before the update):

const CONFIG = {
  bundleDir: path.join(__dirname, 'bundle'),
  mainIndex: 'index.html',
  serverHost: '0.0.0.0',
  serverPort: 8000
}

...

devServer: {
    host: CONFIG.serverHost,
    port: CONFIG.serverPort,
    open: CONFIG.mainIndex,
    contentBase: CONFIG.bundleDir,
    colors: true
}

Now it only works when I specify the contentBase as a command line argument:

"scripts": {
  "server": "webpack-dev-server --content-base bundle",
}

can confirm that this way it works

im actually using
webpack-cli serve --content-base public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants