-
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
Please support webpack v5+ #452
Comments
I have karma-webpack working with webpack v5. I have posted a small repository at: https://github.com/appzuka/karma-webpackv5-test I needed to create a patch to get it working with ts files. |
FWIW I had success with using the dev release of karma-webpack, adding "webpack" to the list of karma frameworks, and ensuring the webpack config I was providing to karma didn't have an diff --git a/webpack/karma.conf.js b/webpack/karma.conf.js
index 62e1808fb0..2961f252b5 100644
--- a/webpack/karma.conf.js
+++ b/webpack/karma.conf.js
@@ -2,8 +2,8 @@
// Karma configuration
// Generated on Thu Apr 02 2015 11:41:22 GMT+0100 (BST)
-var webpackConfig = require("./webpack.config.base.js");
+let webpackConfig = require("./webpack.config.base.js");
+delete webpackConfig.output;
module.exports = function (config) {
config.set({
@@ -12,7 +12,7 @@
webpack: webpackConfig,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
- frameworks: ["jasmine"],
+ frameworks: ["jasmine", "webpack"],
// list of files / patterns to load in the browser
files: [
diff --git a/webpack/package.json b/webpack/package.json
index 21fb8591e5..4eee3b9e97 100644
--- a/webpack/package.json
+++ b/webpack/package.json
@@ -146,7 +146,7 @@
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^4.0.1",
- "karma-webpack": "^4.0.2",
+ "karma-webpack": "dev",
"node-sass": "^4.14.1",
"postcss-loader": "^3.0.0",
"postcss-simple-vars": "^5.0.2", |
Both @appzuka's and @jdelStrother suggestions result in the same output for me (no issue with both webpack@4.44.2 and karma-webpack@4.0.2):
|
Hm, for me that was caused by passing webpack config looking like |
I do not have an output field. This is my webpack configuration within karma.conf.js:
|
From the config above I can see that you are using files with the extension 'es6'. The current next branch assumes that all source files have a 'js' extension. If they do not it will fail with the error you are seeing. I am using 'ts' and 'tsx' file and my PR addresses this, but it will still fail with other extensions. My PR could be extended to work with es6 extensions or perhaps made to cope with non js extensions in general. If you are able to change your extension to js that would be a quick fix. |
@appzuka, thank you. It makes sense although I am not sure why karma-webpack@5 would need to be aware of the file extension before processing through webpack@5 (especially since such configuration works with webpack@4 and karma-webpack@4). In my configuration, es6 files are processed with Babel whereas js files are not. I could easily switch to another extension like mjs, but if I rename all es6 files to js, I need to find another way to distinguish files processed with Babel. |
The line which allows my PR to work with ts and tsx files is: You could extend this to allow es6 files. |
Hey all, I'd just like to apologise for not being able to give this project the love & attention it needs. I'll get to this as soon as I can, I've carved out time at the weekend for it. Work has been hectic and it's taken all of my attention over the last few months. Sorry all, I realise this is a blocker for some and I should've done it sooner. Thanks for your patience also. |
@ryanclark have you thought about adding maintainers? It sounds like there's some in this thread who can help |
I did tweet asking for maintainers and am happy to add more. Shoot me an email to ryan@ryanclark.me if anyone is interested. A release will be out mid week for webpack v5 support |
Welcoming @AprilArcus who has kindly offered to help contribute! & I'm still working on this new release 🙂 |
When using the
There is no |
@ceisele-r, What sort of files do you have in your project? If you have files with any extension other than js (such as ts, tsx, es6, ...) you will see this error. I submitted a PR to make it work with ts and tsx files: |
@appzuka well, it's a typescript project, so it has .js, .ts, .tsx files.
...so babel should transpile it to .js. But, does the line you refer to get called before webpack (and therefore babel) process the files? So does it affect the "raw" project files? |
@ceisele-r, The current 'next' version will not work with TypeScript files. The problem is that karma-webpack caches the files but it assumes they end in '.js' to create a cache key. My PR addresses this but only for ts and tsx files. You could try adding my PR to your project (https://github.com/appzuka/karma-webpack/tree/next). I am able to run karma-webpack with webpack v5 using this PR. The maintainers are working on this repo so hopefully this PR will be merged soon, and perhaps extended to cover other file types. |
@appzuka thanks. With your repo pulled in for
That's the karma config regarding files:
|
@ceisele-r, In the 'next' branch you need to add 'webpack' to your list of frameworks. See: https://github.com/ryanclark/karma-webpack/tree/next So you will need: frameworks: ["mocha", "chai", "webpack"], |
@appzuka wonderful, thanks! Now it seems to work. |
@ceisele-r, I spent a few hours stuck on these issues myself so I'm glad I could share what I learned. Good luck with your project. |
Just an update on where I'm at - it's been so long ago that I was contributing to this project that wrapping my head around it properly to put out a "proper" release with webpack v5 support that isn't hacky is proving difficult. So instead, I've been working on from pretty much a fresh plate to ensure that it's a good quality release. What's peoples thoughts on this? I understand there are some temporary solutions we can put in place to get v5 support out there ASAP - I'm happy to do this alongside what I'm working on too. My main priority is ensuring that everyone is happy and that we have a solid contributor base that isn't just me, so please let me know your thoughts and what I can do. Cheers! |
@ryanclark for us this package is the last remaining blocker on updating to Webpack 5. So a higher priority for me would be adding support first before a clean rebuild. Webpack won’t push another major version (6) for at least a year or 2, so once you have support out the door you should have plenty of time to do a refactor. |
@jasonwilliams sounds good - I'll use a combination of the solutions people have posted here to get a release through. The reason I was going for a rewrite is because I started by upgrading all the node modules, and the API of Thanks for your feedback 🙂 |
@ryanclark, I am using the next branch with Webpack5 so it seems that it is close to being ready, at least for relatively straightforward projects. I would be happy to help investigate any issues. In the release notes for the new version you should highlight the need to include webpack in the list of frameworks as this is easy to overlook. |
Hi, v5.0.0-alpha.2 gives
I'm using webpack-cli v4.2.0, wepack v5.9.0 and karma v5.2.3 |
@veke any reason why you're not using 5.0.0-alpha.3.0 ? |
Ah, did not find that version from the releases. Well, it did not made difference. |
Hi @ryanclark , |
@ryanclark I'm still getting this error Using Thanks for all your effort. Much appreciated! |
@elad-lachmi May or may not be related, but that's the exact error I get if I just pass my base webpack config to Karma, without removing my |
I take that back. I've followed all of the advise in this thread, except what @jdelStrother suggested. EDIT: so now I'm getting these kinds of errors. I believe it's related, because those tests and targets haven't been changed in a while.
EDIT 2: Debugging it a little bit. Seems something similar to #151. In my case EDIT 3: If anyone else hits this exception in flushFirstCallback, it's related to React and not specific to |
Hello, We are also seeing issue while upgrading to WebpackV5. One issue is: -Raag |
Thanks all for the feedback! To those who are experiencing errors still, do you have a small example recreating the issue I can take a look at please? Thank you |
As far as I am concerned (es6 files packaged through babel and webpack):
|
@jlchereau, have you included 'webpack' in the list of frameworks in karma.conf.js? This is new in V5 and if you miss it no tests will execute. See: #452 (comment). My project (which uses TypeScript) works with karma-webpack@5.0.0-alpha.5 and webpack@5.10.0. |
@appzuka, thank you. All good after adding |
Considering how many people have tripped over this ^ is it worth putting something in the readme? |
@jasonwilliams, agreed + section relative to upgrade instructions from v4 to v5 |
A note in bold has been added to the readme: I agree this needs to be very clear in the release notes otherwise a lot of people will miss it. |
Weirdly i get this when upgrading karma-webpack to '5.0.0-alpha.5' and webpack to 5.10.3
I don't get this on the older versions :( It could be related to webpack/webpack#11767 |
I'm getting an error with ERROR in ./node_modules/@angular/material/__ivy_ngcc__/bundles/material-expansion.umd.js
Module build failed (from ./node_modules/string-replace-loader/index.js):
SyntaxError: Unexpected identifier
at Object.processChunk (C:\Workspace\myProject\node_modules\string-replace-loader\lib\processChunk.js:7:24)
@ ./src/app/material.module.ts 32:20-58
@ ./src/app/shared/my-input/my-input.component.spec.ts 17:26-58 It's pointing to this code which seems fine, and works under Webpack v4 with the previous major version of I'd like to troubleshoot it myself but have no idea how to debug whatever |
Follow-up to yesterday's comment: this works if I |
I have a branch for validating that this is the case and throwing a more specific error message. Just looking for some feedback on whether there might be edge cases where it is not required and if throwing an error is the most desirable way to stop execution. |
I also want to document here for anyone running into a similar issue that I was that if you have an entry point set up in your webpack configuration, it will cause your bundled files to not be included and you will get this error.
|
I was going to ask about that last bit -- I got up and running with karma-webpack using a howto article I found online, and one of the things it has you do is import your webpack config with |
A good point, I can add a PR that throws a warning and removes the entry point. |
Hey @ryanclark or @codymikol is Webpack v5 support still in alpha? I don't know how ready this is though so just a suggestion. |
@jasonwilliams We are currently still in alpha, I'm hoping to get a stable release out in the next two weeks |
To limit confusion, I am combining all threads for webpack 5 / karma6 support over here ==> #475 |
v5 is now available |
The text was updated successfully, but these errors were encountered: