should webpack 5.x now be supported? (getting TypeError: Cannot read property 'add' of undefined)
I am now using Angular 11.1.0 and everything to the latest versions except webpack that still on 4.44.2 is compiling and running just fine. But if i upgrade webpack to 5.17.0 with "ng update webpack" (it doesn't complain anymore about not supported versions)
and when i then try to compile i get this compile error:
ng build --prod --subresourceIntegrity=true
An error occurred during the build:
TypeError: Cannot read property 'add' of undefined
at xxx\node_modules@ngtools\webpack\src\ivy\plugin.js:147:86
at Array.forEach (
Webpack 5 support is currently experimental but the team is moving toward stable default support in a future major release. You can try out Webpack 5 with 11.x by using yarn as the project's package manager and adding the following package resolution option to the project's package.json:
"resolutions": {
"webpack": "^5.4.0"
}
The majority of options and features should be functional. However, it is not recommended for production use at this time. If you encounter any problems after following the above steps, please open an issue describing the problem.
i am in no hurry to go to 5. But i just saw quite a few webpack issues (here i think and in angular itself) that i think are all closed So didn't know what the current status of it really is. (i kind of expect an open bug like "Support WebPack 5" where comments are made on and commits are based on)
@jcompagner, is the problem still persistent after using the above mentioned yarn resolutions?
I do find that long lived issues are not as valuable as seperate issues for each problem. As it would be harder to get reproductions while also the discussion can easily go off-topic.
don't need that "resolutions" (but just "webpack": "5.17.0", under dependencies) but then just using yarn instead of npm does compile my project.
Closing as it appears that the user no longer experiencing the problem.
If the problem persists, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. You can use ng new repro-app to create a new project where you reproduce the problem.
I have absolutely the same error with the same stacktrace and to repro it you just need to install additionally webpack version >= 5 after ng new ....
but what if I don't have yarn? I know that I can move to yarn but what's actually the difference? why does it work with yarn but don't with npm?
as I understand angular-cli packages don't support webpack>=5 for now but yarn via resolutions option can allow override a version of a particular nested dependency and for author it works even more for him it also works without that option. what's going on? :)
can I somehow use webpack5+ with custom builders or use my own webpack config via @angular-devkit/build-webpack?
that resolutions of yarn has nothing to do with this.
i didn't change anything to the package.json compard to "npm install" or "yarn install"
and with yarn it compiled.
I am also very curious what that exactly is what the package manager then really does (what is different in the layout of node_modules , you would say that is kind of standard right?)
but anyway, i am not planning to use yarn (locally that would be fine, but later that could be a problem in how we need to use this). So i will just wait for more official webpack 5.x support that then also works with just npm (or maybe npm7 also fixes this?) maybe angular 12? for now i keep to the latest 4.x
ah, you stayed with 4.x... now is clear and sad simultaneously. I thought there are a workarounds at least temporary to use 5.x because I really didn't wont to downgrade my custom webpack config to 4th version but as I understand I'll have to otherwise I will struggle with angular ecosystem as with windmills. thanks for the update.
Without the resolutions addition, the build will use Webpack 4 and not 5. This is because Webpack is a direct dependency of the build system package (@angular-devkit/build-angular) and the version specified in that package will be used (currently 4.44.2) to initialize Webpack. The resolution ensures that one specific version of Webpack is used throughout the install. By installing Webpack 5 in the project and not using the resolution, some packages that were hoisted by the package manager may errantly use Webpack 5 even though the build itself will use Webpack 4. This is most likely the cause of the original error.
For npm, there are some third-party packages (e.g., npm-force-resolutions) that attempt to adjust the package lock file to mimic the behavior of yarn resolutions. However, using yarn is currently the recommended method for enabling experimental Webpack 5 support.
ahh could it be that because of that yarn did work? under the hood it still just uses webpack 4?
npm for sure uses webpack 5 if i pust that in my package.json. because i only change my package.json form 4.x to 5.x -> npm install -> npm run build ->breaks change back to 4.x -> npm install -> npm run build -> works
and doing this: package.json form 4.x to 5.x -> yarn install -> yarn run build -> works.
but are you saying that having webpack in my package.json is kind of not needed at all (i don't use it directly) i can just depend on what angular-cli takes in?
ok tested this, i guess yarn installs peer dependencies? and npm doesn't do that? this way you can just use another version of webpack with npm just the one that you install and specify in the package.json
(npm 7 will also install peer dependencies, i guess then they also need that extra configuration to overwrite it again, so that something similar to yarns resolutions thing?)
@clydin recommended to use npm-force-resolutions and it fixes issue with different webpack versions so angular builder reuses one which you defined in resolutions property. then you need to dedupe invalid peer dependences via npm dedupe and everything should... start building. I'm not sure does it work correctly but I got same build errors when I tried to start project on webpack 4.x.
ps; this package has some edge cases and I hope no one will shoot in future.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.