webpack: Code-splitting creates request for "undefined.js" 404

Using version webpack@1.3.7

I’ve started using code-splitting and it seems webpack --watch start outputting broken bundles as soon as I make a change to any file, it’s fixed by just restarting the process (which makes watching pointless).

Chrome outputs the following error to the console:

GET http://.../static/undefined.js 404 (OK)
output: {
  path: '/...',
  filename: 'static/[name].js',
  chunkFilename: 'static/[chunkhash].js'
}

I’m assuming [chunkhash] for some reason become undefined when it’s rebuilding the bundle.

PS. The terminal does not seem to print any errors and the bundle is correctly named there:

              static/bundle.js   379082       1  [emitted]  bundle
static/b8585b0346bbe807fec7.js  1291905       2  [emitted]

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 28 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Got the same problem but with webpack.js@2.2.1 — one of two entries requests /dist/1-undefined.js (example repo https://github.com/zemlanin/dynamite)

// webpack.config.js
const path = require('path')
const webpack = require('webpack')

module.exports = {
  entry: {
    main: './main.js',
    pain: './pain.js',
  },
  output: {
    filename: '[name].js',
    chunkFilename: '[id]-[chunkhash].js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: 'dist/',
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /(node_modules)/,
      use: [{
        loader: 'babel-loader',
        options: {
          presets: [['es2015', {modules: false}]],
          plugins: ['syntax-dynamic-import']
        }
      }]
    }]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      names: ['main', 'pain'],
      async: true,
      minChunks: (module, count) => /node_modules/.test(module.userRequest),
    }),
  ],
}
$ npm run webpack -- --hide-modules; grep 'script.src = __webpack_require__.p' dist/pain.js dist/main.js
...
Version: webpack 2.2.1
Time: 903ms
                    Asset       Size  Chunks             Chunk Names
0-fdfde16e569cd099cda0.js  650 bytes       0  [emitted]  
1-697132204232dcb21be2.js    30.4 kB       1  [emitted]  
2-6521e81a926120e1048d.js    1.56 kB    2, 3  [emitted]  
3-eaee5cac6bd576a1a204.js    1.07 kB       3  [emitted]  
                  pain.js    20.9 kB       4  [emitted]  pain
                  main.js    21.3 kB       5  [emitted]  main
dist/pain.js:/******/ 		script.src = __webpack_require__.p + "" + chunkId + "-" + {"0":"fdfde16e569cd099cda0"}[chunkId] + ".js";
dist/main.js:/******/ 		script.src = __webpack_require__.p + "" + chunkId + "-" + {"0":"fdfde16e569cd099cda0","1":"697132204232dcb21be2","2":"6521e81a926120e1048d","3":"eaee5cac6bd576a1a204"}[chunkId] + ".js";