Skip to content
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

webpack output is served from undefined #2745

Closed
loadingwyn opened this issue Sep 24, 2020 · 2 comments · Fixed by #2913
Closed

webpack output is served from undefined #2745

loadingwyn opened this issue Sep 24, 2020 · 2 comments · Fixed by #2913

Comments

@loadingwyn
Copy link

Describe the bug

The output of webpack doesn't get served.

What is the current behavior?

image

My config:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  entry: './index.ts',
  context: path.resolve(__dirname),
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader', 'postcss-loader'],
      },
    ],
  },
  devServer: {
    contentBase: './demo',
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },

};

Command:

webpack serve --config ./demo/webpack.config.js --mode development --open chrome

To Reproduce

Steps to reproduce the behavior:

  1. Define a devServer config in your webpack config file
  2. Run webpack serve --config webpack.dev.js

Expected behavior

The output js file can be served by dev server

Additional context

image

@alexander-akait alexander-akait transferred this issue from webpack/webpack-cli Sep 24, 2020
@cyyynthia
Copy link

I've encountered this issue on my end and after some digging, it appears specifying publicPath inside devServer options in my config solved it.

{
  ...,
  devServer: {
    ...,
    publicPath: '/dist'
  }
}

@dwiyatci
Copy link

dwiyatci commented Oct 27, 2020

@Bowser65 🤦🏻‍♂️ isn't that weird? If devServer.publicPath not specified, it should actually fallback/be default to '/'.

https://webpack.js.org/configuration/dev-server/#devserverpublicpath-

🤷🏻‍♂️

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

Successfully merging a pull request may close this issue.

3 participants