enhanced-resolve icon indicating copy to clipboard operation
enhanced-resolve copied to clipboard

NormalModuleFactory.afterResolve is no longer a waterfall hook

Open robatwilliams opened this issue 5 years ago • 5 comments

When I tried Webpack 5 RC 0, I received the following error. It looks like this module may be the cause.

[email protected]
[email protected]
[email protected]
C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:251
                                                        throw new Error(deprecationChangedHookMessage("afterResolve"));
                                                        ^

Error: NormalModuleFactory.afterResolve is no longer a waterfall hook, but a bailing hook instead. Do not return the passed object, but modify it instead. Returning false will ignore the request and results in no module created.
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:251:14
    at Hook.eval [as callAsync] (eval at create (C:\Projects\MyProject\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:14:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\Projects\MyProject\node_modules\webpack\node_modules\tapable\lib\Hook.js:18:14)
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:247:30
    at eval (eval at create (C:\Projects\MyProject\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:13:1)
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:481:7
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:116:11
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:513:8
    at NormalModuleFactory.resolveRequestArray (C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:734:34)
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:505:11
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:116:11
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:585:8
    at C:\Projects\MyProject\node_modules\webpack\lib\NormalModuleFactory.js:721:5
    at finishResolved (C:\Projects\MyProject\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:267:11)
    at C:\Projects\MyProject\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:329:25
    at C:\Projects\MyProject\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:396:24

In particular, the returning here:

// at finishResolved (C:\Projects\SaxoTrader\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:267:11)
const finishResolved = result => {
  return callback(
    null,
    result.path === false
      ? false
      : `${result.path}${result.query || ""}${result.fragment || ""}`,
    result
  );
};

robatwilliams avatar Sep 21 '20 11:09 robatwilliams

Please create reproducible test repo

alexander-akait avatar Sep 21 '20 12:09 alexander-akait

I'm not sure if I'll be able to do that I'm afraid. The modules involved all appear to be internal to webpack, we're not using them directly. Our build is large/complex with many plugins/loaders and can't be pared down to a reproduction case.

It only happens when using webpack-dev-middleware (3.7.2, which is compatible with webpack 5).

I'm ok if you want to close this, I'll reopen if I find any lines of investigation, and I'll try the next RC when it's released.

robatwilliams avatar Sep 21 '20 14:09 robatwilliams

I think bug in plugin/loader, I can't help without configuration

alexander-akait avatar Sep 21 '20 14:09 alexander-akait

This is a breaking change in webpack 5, but the error message is not very helpful in finding the offending plugin.

We should improve the error message.

sokra avatar Sep 21 '20 18:09 sokra

By a process of elimination I found that https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/27 was the issue, which has been fixed but yet to be released.

Agree with keeping this issue to improve the error message, thanks

robatwilliams avatar Sep 28 '20 11:09 robatwilliams