Webpack-dev-server: "lazy" mode does not seem to work in the latest webpack-dev-server

Created on 26 Feb 2018  Â·  20Comments  Â·  Source: webpack/webpack-dev-server

  • Operating System: Windows 10 (crosschecked on Ubuntu 17.10)
  • Node Version: 8.4.0
  • NPM Version: 5.6.0
  • webpack Version: 4.0.0 (first spotted on 3.x)
  • webpack-dev-server Version: 3.0.0 (first spotted on 2.x)
  • [x] This is a bug
  • [ ] This is a modification request

Code

https://github.com/sergebat/test-webpack-lazymode

'use strict';

module.exports = {
  entry: './app.js',
  mode: "development",
  output: {
    filename: "bundle.js"
  },
  devServer: {
    lazy: true,
    inline: false,
    filename: "bundle.js"
  }
};

Expected Behavior

http://localhost:8080/bundle.js should return bundle in Lazy mode when loaded in browser.

Actual Behavior

Browser displays: "Cannot GET /bundle.js".

If lazy: true is removed, bundle.js returns fine.

I tried http://localhost:8080/dist/bundle.js, tried removing optional filename in devServer, tried removing inline: false. Neither of these options worked for me.

For Bugs; How can we reproduce the behavior?

Sync repo at https://github.com/sergebat/test-webpack-lazymode, then:

npx webpack-dev-server

and open bundle in browser.

For Features; What is the motivation and/or use-case for the feature?

3 (broken) approved

All 20 comments

I'm not running in lazy mode, but I have found that if I set inline: false that I appear to get a jQuery deferred error. If I remove inline: false and go with the default everything works fine. This is unfortunate however, because I'm requesting an asset from webpack-dev-server for another app, if I don't set inline: false it reloads the whole page for my non-webpack app.

Here is the error:

jQuery.Deferred exception: n(...) is not a function TypeError: n(...) is not a function
    at HTMLDocument.<anonymous> (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:163209)
    at c (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:105849)
    at l (https://localhost:8080/__webpack_dev_server__/live.bundle.js:1:106151) undefined
T.Deferred.exceptionHook @ live.bundle.js:1

@scottsword this will be fixed in next release (fixed in #1329)

@sergebat, webpack-dev-server only passes the lazy option to webpack-dev-middleware; so I think the issue is in that package.

@SpaceK33z thanks. I'll try to reproduce with raw 'webpack-dev-middleware' over weekend, and if it occurs there, will create and link issue there.

@SpaceK33z thanks man, I saw that someone added a fix for it yesterday, just hasn't made its way out. For posterity, the issue I encountered was different than OP's and was fixed with this commit - https://github.com/webpack/webpack-dev-server/commit/f2db057ac105ec945f0e62dba64441c4ccfde59c

@SpaceK33z interestingly enough, things seem work fine on webpack-dev-middleware:
https://github.com/sergebat/test-webpack-lazymode/blob/master/testmw.js

File above works fine on Ubuntu node testmw.js for me (not on Windows, as things seem to be broken there the hard way, but that's another issue I guess https://github.com/webpack/webpack-dev-middleware/issues/270)

At the same time, node_modules/.bin/webpack-dev-server displays "Cannot GET /bundle.js" for me on Ubuntu.

In case it helps someone diagnose the issue, it starts to work if path is explicitly and incorrectly specified like this:

'use strict';

module.exports = {
  entry: './app.js',
  mode: "development",
  output: {
    filename: "bundle.js",
    path: "/" // <- :) 
  },
  devServer: {
    lazy: true
  }
};

Thanks for figuring this out.

Setting the filename option fixed the problem in my case :

devServer: {
  lazy: true,
  filename: 'index.html',
}

This issue is still there, I tried all the above-mentioned solutions and no one works. I'm just following the guides and I just tried to play with the different options when I reached the Development section.

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackManifestPlugin = require('webpack-manifest-plugin');

const distFolder = path.resolve(__dirname, 'dist');
const filename = 'bundle.js';

module.exports = {
  mode: 'development',
  entry: {
    app: './src/index.js',
    print: './src/print.js'
 },

  plugins: [
    new CleanWebpackPlugin(distFolder),

    new HtmlWebpackPlugin({
      title: 'Hello from Output Management'
    })
  ],

  devtool: 'inline-source-map',

  devServer: {
    open: true,
    contentBase: distFolder,
    port: 8008,
    compress: true
  },
  output: {
    filename: filename,
    path: distFolder
  }
}

Oooooooookey. i found it

public/index.html

<script src="/bundle.js"></script>

src/index.js

console.log('works');

webpack.config.js

const path = require('path');

module.exports = {
  entry: './src/index.js',

  output: {
    filename: 'index.html',
    // production
    // path: path.resolve('./dist'),
    // dev
    path: '/',
  },

  devServer: {
    contentBase: path.resolve(__dirname, 'public'),
    lazy: true,
  },
};

package.json

{
  "dependencies": {
    "webpack": "^4.32.2",
    "webpack-dev-server": "^3.4.1",
    "webpack-cli": "^3.3.2"
  },
  "scripts": {
    "start": "webpack-dev-server --config webpack.config.js",
    "build": "webpack --config webpack.config.js"
  }
}

So problem already solved? If not please create actual minimum reproducible test repo, thanks

it doesnt work with HtmlWebpackPlugin, but should

@notiv-nt Speciously? __If not please create actual minimum reproducible test repo, thanks__

Thanks

1: Why?

output: {
  // Production
  // path: path.resolve('./dist'),
  // Dev, yarn build throws an error
  path: '/',
},

2:

dev-server should run plugins on start

What you mean? Please clarify

  1. output.path — absolute path
    https://webpack.js.org/configuration/output#outputpath

  2. htmlwebpackplugin does not work in webpack-dev-server

👀

Lazy was removed from webpack-dev-middleware due incompatibility with webpack and will be removed in next release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikirossi picture nikirossi  Â·  3Comments

antoinerousseau picture antoinerousseau  Â·  3Comments

mischkl picture mischkl  Â·  3Comments

daryn-k picture daryn-k  Â·  3Comments

gimmi picture gimmi  Â·  3Comments