Skip to content
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

Regression in 5.69.0: result is not iterable #15409

Closed
nwalters512 opened this issue Feb 16, 2022 · 4 comments · Fixed by #15423
Closed

Regression in 5.69.0: result is not iterable #15409

nwalters512 opened this issue Feb 16, 2022 · 4 comments · Fixed by #15423

Comments

@nwalters512
Copy link

Bug report

What is the current behavior?

When I try to build my application, it fails with the following error message and stack trace:

TypeError: result is not iterable
    at /Users/nwalters/git/global-markup/node_modules/webpack/lib/cache/ResolverCachePlugin.js:258:42
    at /Users/nwalters/git/global-markup/node_modules/webpack/lib/cache/ResolverCachePlugin.js:177:28
    at /Users/nwalters/git/global-markup/node_modules/webpack/lib/HookWebpackError.js:68:3
    at Hook.eval [as callAsync] (eval at create (/Users/nwalters/git/global-markup/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at Cache.store (/Users/nwalters/git/global-markup/node_modules/webpack/lib/Cache.js:107:20)
    at ItemCacheFacade.store (/Users/nwalters/git/global-markup/node_modules/webpack/lib/CacheFacade.js:137:15)
    at /Users/nwalters/git/global-markup/node_modules/webpack/lib/cache/ResolverCachePlugin.js:171:18
    at jobDone (/Users/nwalters/git/global-markup/node_modules/webpack/lib/FileSystemInfo.js:1966:5)
    at FileSystemInfo.createSnapshot (/Users/nwalters/git/global-markup/node_modules/webpack/lib/FileSystemInfo.js:2301:3)
    at /Users/nwalters/git/global-markup/node_modules/webpack/lib/cache/ResolverCachePlugin.js:155:21

If the current behavior is a bug, please provide the steps to reproduce.

Unfortunately, I don't understand enough of webpack's internals to even begin to try to reproduce this error in isolation. I also can't share the app or config directly, as they're internal to my company. I did do some investigation via console.log statements inside ResolverCachePlugin.js, which I'll share here.

The error in the above stack trace is thrown on this line:

if (result) for (const r of result) yield_(r);

If I look at the value of result when it fails, I see that indeed it is an object, not an array (or any other kind of iterable).

I added the following logs below this line in ResolverCachePlugin.js:

console.log('identifier', identifier, 'withYield', withYield)
console.log('resolveContext', resolveContext);

I noticed that the vast majority of the identifier values start with normal|default|, but the identifier associated with the failing stack trace starts with context|yield. This makes sense, as this occurs inside the withYield branch of code:

const done = withYield

I followed the stack trace back to this line of code:

const resolveResult = result || yieldResult;

If I log there, I see that both result and yieldResult are defined. yieldResult is an empty array, and result is an object. I suspect that this is the root of the problem: the done callback seems to expect that for any resolver that is withYield, that the result will be an iterable, but resolveResult (which is ultimately passed to done) is actually an object in this case.

This code was recently modified in #15332, including the addition of the const resolveResult = result || yieldResult; code, so I'm pretty confident that this regression can be traced back to that PR.

I sincerely apologize that I'm unable to provide a reproduction, and I'd be happy to answer any questions about the structure or specific nature of my project.

What is the expected behavior?

I would expect to not see this error. On webpack 5.68.0 and previous versions (all the way back to v4), I did not see this error.

Other relevant information:
webpack version: 5.69.0
Node.js version: 16.13.1
Operating System: macOS

@nwalters512
Copy link
Author

cc @vankop, since it looks like you're pretty familiar with this code!

@vankop
Copy link
Member

vankop commented Feb 17, 2022

@nwalters512 Could you provide a repro? I think I found problem

@vankop
Copy link
Member

vankop commented Feb 17, 2022

@nwalters512 Could you reduce repro to this resolve request? steps to reduce:

  • reduce webpack config to resolve settings only ( and cache: true will be enough)
  • in debug you can find request that webpack trying to resolve
  • reduce repo to result of this resolve (e.g. should resolve folder N)

@nwalters512
Copy link
Author

nwalters512 commented Feb 17, 2022

@vankop Thanks for taking a look! I was ultimately able to isolate the parts that are causing problems: https://github.com/nwalters512/webpack-resolver-cache-plugin-bug-repro. Please follow the instructions in the README to reproduce.

In doing so, I realized that the error only occurs with a custom webpack plugin that we use to deduplicate dependencies, which is located at deduple-plugin.js (original, non-transpiled TS code available in dedupe-plugin.ts). If I remove the plugin, the error goes away. It's entirely possible that our plugin is doing something stupid and that the resolution will be to change the plugin, not webpack. However, the plugin definitely worked on webpack v5.68.0 and v4.x, so I think there's still the possibility that this is a genuine regression in webpack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants