rewire-webpack
rewire-webpack copied to clipboard
enhanced-resolve doesn't always have /lib/ModuleAliasPlugin.js
I currently have a project with enhanced-resolve v3.4.1 and it doesn't have /lib/ModuleAliasPlugin.js
; this causes RewirePlugin.js
to fail in line 48.
See also: https://github.com/webpack/enhanced-resolve/tree/master/lib
Additionally, in webpack the resolvers are initialised with null
in the Compiler constructor and you cannot use apply on null: https://github.com/webpack/webpack/blob/master/lib/Compiler.js#L184
Same problem here. Getting TypeError: Cannot read property 'apply' of null
as a consequence of the mentioned problem.
For everyone having the same problem: You can use babel and babel-rewire-plugin. It sidesteps the issue (rewire is then handled by babel) and is a nice workaround to get unblocked.
Can you provide an example :)?
For what, exactly? Using babel-rewire or for the issue described?
Well, I'm not sure but I guess a karma / wepack config file example :)? It's just so I understand how you use Babel-rewire as a workaround :)
Its nothing special about what I did. I just used a different set of frameworks. Instead of going karma -> webpack -> webpack-rewire -> mocha/chai I now use karma -> webpack -> babel -> babel-plugin-rewire -> mocha/chai
You can check out the babel plugin here: https://github.com/speedskater/babel-plugin-rewire
Sweet, thanks for the help ! I'll be looking into it. The only thing I am worried about when using babel is that I've always used webpack, and I am testing a lib that is packed with it. But I guess for unit testing it doesn't really matter how you pack scripts. I am somehow worried that packing something differently in a testing environment and in a production environment could cause issues :/
My setup still uses webpack :)
For a solution without babel, you can use my fork rensbaardman/rewire-webpack-plugin, which has webpack 4 support.