-
Notifications
You must be signed in to change notification settings - Fork 222
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
webpack5: getPathKey returns key not in bundlesContent; leads to sha1(undefined) in karma #453
Comments
(The fix in #451 doesn't help, but that's not surprising as this is pure js, not typescript.) |
What did help in my case was: - const bundleContent =
- controller.bundlesContent[getPathKey(file.path, true)];
+ let key = `js/${getPathKey(file.path)}-`;
+ key = Object.keys(controller.bundlesContent).find((name) => name.startsWith(key));
+ const bundleContent = controller.bundlesContent[key]; |
Ok, it is coming from the webpack config, via So... I can fix this on my side, by explicitly forcing Feel free to close this .. but maybe you want to override that / warn about it / handle that case? |
It seems that this error happens in a few cases when the webpack configuration has an invalid field, I have a similar issue over here. #458. I think we can treat this in the same way, I just want to verify that these are required settings and that we won't break anyones environment by setting these automatically and warning about invalid configuration. |
To limit confusion, I am combining all threads for webpack 5 / karma6 support over here ==> #475 |
v5 is now available |
I'm using webpack 5.28.0 and karma-webpack 5.0.0 and I'm still getting the |
I'm using webpack 5.38.1 and karma-webpack 5.0.0-alpha.6 and still getting
My karma conf const path = require('path')
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// mime: {
// 'text/x-typescript': ['ts', 'tsx']
// },
frameworks: ['mocha', 'chai', 'webpack'],
// list of files / patterns to load in the browser
files: [
// { pattern: '', included: false },
// 'dist/NIM_BROWSER_SDK.js',
// 'test/**/*.spec.js'
'test/index.ts'
],
// list of files / patterns to exclude
exclude: [
// 'dist/NIM_BROWSER_SDK.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
// preprocessors: {
// 'test/**/*.spec.js': ['webpack']
// },
preprocessors: {
'test/index.ts': ['webpack']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter
// reporters: ['nyan', 'coverage-istanbul'],
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: !!process.env.CI,
concurrency: Infinity,
webpackMiddleware: {
noInfo: true,
stats: 'errors-only'
},
webpack: {
mode: 'development',
entry: './src/entry/browser.ts',
output: {
filename: '[name].js'
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'test/tsconfig.json'
}
},
exclude: [path.join(__dirname, 'node_modules')]
},
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json']
}
},
})
} My test file in test/index.ts
|
I set
It's weird. My karma config is in the comments above |
Did you update to karma-webpack v5.0.0 ? |
I had the same issue with karma-webpack v5.0.0, but only on macOS. No issue whatsoever on Linux & Windows machines. Changing this line: to |
The changes bewteen master and v5.0.0 also fix this issue, could you do a v5.0.1 release with them? |
Which change specifically? Something in ef7edb6 ? |
Yes, I think these changes are the ones: ef7edb6#diff-282d7a470af0c4d49f499674bcd6d416cdc3ad49918bb564a2ae5e3e8dad81ccR86-R96 |
Strange, that doesn't actually change anything. It just replaces |
I think the error is related to async/promise and the code in https://github.com/karma-runner/karma/blob/2b71a3c6a01757e0b5c1bf8d241b588656b62127/lib/preprocessor.js#L47-L55, especially the branch doing From v5.0.0/e2423b47ec59059bc1808c670affa64d0f5aa8b7, changing My understanding is that |
UpdateSolved with removing some entries from preprocessors: {
'src/**/*Spec.js': ['webpack'],
- 'test/**/*.js': ['webpack']
}, Original commentSimilar issue here. Using:
getting:
|
Expected Behavior
using
'./client/app.js': ['webpack']
inkarma.conf
preprocessors
, processing that file should work.(With an otherwise working webpack config.)
Actual Behavior
in
karma/lib/preprocessor.js
, the failingfile
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'sundefined
.In
karma-webpack/lib/karma-webpack.js
, afterawait controller.bundle()
inprocessFile
:bundleContent
isundefined
,getPathKey(file.path, true)
returnsapp.1564016497.js
,while the only keys matching
/app/
incontroller.bundlesContent
are: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?
The text was updated successfully, but these errors were encountered: