karma-webpack: webpack5: getPathKey returns key not in bundlesContent; leads to sha1(undefined) in karma

  • Operating System: linux
  • Node Version: 14
  • NPM Version: yarn 1.22
  • webpack Version: 5.3.0 (webpack-cli 4.1.0)
  • karma-webpack Version: #next, 5.0.0-alpha.3.0

Expected Behavior

using './client/app.js': ['webpack'] in karma.conf preprocessors, processing that file should work. (With an otherwise working webpack config.)

Actual Behavior

27 10 2020 21:49:28.041:ERROR [karma-server]: UnhandledRejection: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
27 10 2020 21:49:28.042:ERROR [karma-server]: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Hash.update (internal/crypto/hash.js:84:11)
    at Object.sha1 (/home/himdel/manageiq-ui-service/node_modules/karma/lib/utils/crypto-utils.js:9:8)
    at runProcessors (/home/himdel/manageiq-ui-service/node_modules/karma/lib/preprocessor.js:82:26)
    at async FileList.preprocess [as _preprocess] (/home/himdel/manageiq-ui-service/node_modules/karma/lib/preprocessor.js:146:5)
    at async Promise.all (index 0)
    at async /home/himdel/manageiq-ui-service/node_modules/karma/lib/file-list.js:90:11
    at async Promise.all (index 9) {
  code: 'ERR_INVALID_ARG_TYPE'

in karma/lib/preprocessor.js, the failing file is '/home/himdel/manageiq-ui-service/client/app.js' (the only file using the webpack preprocessor), initial content before the webpack preprocessor is the file content, after the webpack preprocessor, it’s undefined.

In karma-webpack/lib/karma-webpack.js, after await controller.bundle() in processFile: bundleContent is undefined, getPathKey(file.path, true) returns app.1564016497.js, while the only keys matching /app/ in controller.bundlesContent are:

    'sass/_app_urls.sass',
    'sass/_app_colors.sass',
    'js/app.1564016497-3d658aca95fc6995589c.js',
    'js/app-208bf5b45fa818efa9cf.js'

So looks like webpack5 is adding a prefix and a hash suffix, which getPathKey doesn’t handle.

Do I need to override some part of webpack config so that it doesn’t do that for tests, or is this an actual bug?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

So looks like webpack5 is adding a prefix and a hash suffix, which getPathKey doesn’t handle.

Ok, it is coming from the webpack config, via output.filename.

So… I can fix this on my side, by explicitly forcing config.output.filename = '[name].js' in webpack testing config.

Feel free to close this … but maybe you want to override that / warn about it / handle that case?