webpack-dev-middleware icon indicating copy to clipboard operation
webpack-dev-middleware copied to clipboard

Old files are being served in dev mode, restarting server, clearing cache does not help

Open Foxhoundn opened this issue 7 years ago • 10 comments

I can literally delete all app files, wait for recompile, shut down the server, start the server, go to the url and the app loads like I didn't delete nothing - what's going on?

Some info:

  • Version used was 1.12.*
  • Starting the server with babel-node server.js

Webpack config -

// @flow
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

// Root path
const root = path.resolve(__dirname, './');

module.exports = {
  mode: 'development',
  context: `${root}/src`,
  entry: {
    qorus: [`${root}/src/index.jsx`],
  },
  output: {
    path: `${root}/dist`,
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    publicPath: '/',
  },
  resolve: {
    modules: [`${root}/src/js`, 'node_modules'],
    extensions: ['.js', '.jsx'],
  },
  cache: false,
  devtool: 'eval-source-map',
  module: {
    rules: [
      {
        test: /\.js(x)?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.(html|mp3|ttf|woff|woff2|eot|svg)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
            },
          },
        ],
      },
      {
        test: /\.(c|sc)ss$/,
        use: [
          'style-loader',
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader',
        ],
      },
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
            },
          },
        ],
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'css/base.css',
    }),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
    }),
    new webpack.ProvidePlugin({
      Promise:
        'imports-loader?this=>global!exports-loader?global.Promise!es6-promise',
      fetch:
        'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
    }),
    new webpack.NoEmitOnErrorsPlugin(),
  ],
};

Server config

// @flow
const express = require('express');
const history = require('connect-history-api-fallback');
const serveStatic = require('serve-static');

const config = require('./webpack.config');
const devConfig = require('./webpack.config/dev');
const serverConfig = require('./server_config');
const WebpackDevServer = require('webpack-dev-server');
const proxyMiddleware = require('http-proxy-middleware');

const app = express();
const env = app.get('env');

if (env === 'production') {
  app.use(history());
  app.get('*', serveStatic(config.output.path));
} else {
  // Get webpack
  const APIconfig = require('./server_config.js');
  const webpack = require('webpack');
  // Get the webpack compiler
  const compiler = webpack(config);

  app.use((req, res, next) => {
    const router = new express.Router();

    router.use(proxyMiddleware(APIconfig.restBaseUrl));
    router.use(proxyMiddleware(APIconfig.extensionProxy));
    router.use(proxyMiddleware(APIconfig.dbProxy));
    router.use(proxyMiddleware(`${APIconfig.wsBaseUrl}/log`));
    router.use(proxyMiddleware(`${APIconfig.wsBaseUrl}/apievents`));

    router(req, res, next);
  });

  /* app.use(proxyMiddleware(APIconfig.restBaseUrl));
  app.use(
    proxyMiddleware('/apievents', {
      target: `${APIconfig.wsBaseUrl}/apievents`,
      ws: true,
    })
  );*/

  // History
  app.use(history());

  // Dev server
  app.use(
    require('webpack-dev-middleware')(compiler, {
      contentBase: config.context,
      inline: true,
      host: process.env.HOST || 'localhost',
      port: parseInt(process.env.PORT, 10) || 3000,
      historyApiFallback: true,
      publicPath: config.output.publicPath,
      noInfo: false,
      stats: { colors: true },
    })
  );

  // Serving
  app.get('*', serveStatic(config.context));
}

// Dev config
const dConfig = devConfig();

app.listen(dConfig.port, dConfig.host, () => {
  process.stdout.write(
    `Qorus Webapp ${app.get('env')} server listening on ` +
      `http://${serverConfig.host}:${serverConfig.port}\n`
  );
});

Please help

  • Webpack does complain about missing files but the app works in the browser which means the bundle is cached somewhere who knows where screenshot 2019-01-14 at 13 16 17

Foxhoundn avatar Jan 14 '19 12:01 Foxhoundn

I'm closing on 35 hours on SOLELY this issue, please any help is appreciated. I've tried everything i've found on the net, restarting computer, but NOTHING is making webpack-dev-middleware serve latest files.

  • Upgraded to 3.50
  • Tried everything in this massive thread - https://github.com/webpack/webpack-dev-server/issues/875
  • Tried various server modifications - serving index.html directly, adding .invalidate()...

I can see in webpack that the latest js bundle is there. It's just not being served. Nothing is helping, how can a file stay in memory after a mac restart?

Is there a .cache folder I can delete or something?

Foxhoundn avatar Jan 15 '19 00:01 Foxhoundn

Please create minimum reproducible test repo

alexander-akait avatar Jan 15 '19 09:01 alexander-akait

Most likely browser cache?

evenstensberg avatar Jan 15 '19 16:01 evenstensberg

This was caused by http-proxy-middleware package, for some reason it was causing wdm to serve some ancient files. All is safe and sound. Sorry for the confusion!

Foxhoundn avatar Jan 15 '19 16:01 Foxhoundn

This was caused by http-proxy-middleware package, for some reason it was causing wdm to serve some ancient files. All is safe and sound. Sorry for the confusion!

So can you give a hint what you did? I am having the same problem.

Conversional avatar Feb 17 '20 16:02 Conversional

I ran into this issue a while a go and it turned out to be that there was an error during the build. I missed the error message as it was at the top of the log. Dev server then serves the last successful build

ButchMonkey avatar Feb 19 '20 08:02 ButchMonkey

I ran into this and found that it was one of the various caches in node_modules/.cache. Deleting the .cache folder instantly fixed the problem for me.

image

ascott18 avatar Jul 02 '20 21:07 ascott18

@Foxhoundn what was the fix?

matthias-ccri avatar May 13 '22 16:05 matthias-ccri

I had been running dev in yarn and then for whatever absentminded reason was running it in npm one day and kept getting this problem. Switching back to yarn dev did the trick.

carterchadams avatar Oct 05 '22 16:10 carterchadams

I have same problem and I suspect it's caused by browser because of I find it happens on my Eadge rather than Chrome.

neil-ji avatar Jul 31 '23 07:07 neil-ji