rewire-webpack icon indicating copy to clipboard operation
rewire-webpack copied to clipboard

enhanced-resolve doesn't always have /lib/ModuleAliasPlugin.js

Open robin-surge opened this issue 7 years ago • 9 comments

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

robin-surge avatar Sep 08 '17 16:09 robin-surge

Same problem here. Getting TypeError: Cannot read property 'apply' of null as a consequence of the mentioned problem.

gempain avatar Sep 11 '17 09:09 gempain

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.

robin-surge avatar Sep 13 '17 16:09 robin-surge

Can you provide an example :)?

gempain avatar Sep 13 '17 17:09 gempain

For what, exactly? Using babel-rewire or for the issue described?

robin-surge avatar Sep 13 '17 17:09 robin-surge

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 :)

gempain avatar Sep 13 '17 18:09 gempain

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

robin-surge avatar Sep 13 '17 18:09 robin-surge

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 :/

gempain avatar Sep 13 '17 18:09 gempain

My setup still uses webpack :)

robin-surge avatar Sep 13 '17 19:09 robin-surge

For a solution without babel, you can use my fork rensbaardman/rewire-webpack-plugin, which has webpack 4 support.

rensbaardman avatar Jun 12 '19 13:06 rensbaardman