webpack: Filesystem Cache is throwing TypeError: Cannot read property 'length' of undefined from ResolverCachePlugin

Bug report

What is the current behavior?

Attempting to get the cache working for webpack 5. I have it working on one of my local repos, but this one (a clone of a different website), is throwing an error:

Relevant config:

  cache: {
    type: 'filesystem',
    buildDependencies: {
      config: [ '/Users/xxx/public-web/config/webpack.config.js' ]
    }
  }

Throws this error:

(node:23491) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at getType (/Users/xxx/public-web/node_modules/enhanced-resolve/lib/util/path.js:41:12)
    at Resolver.isPrivate (/Users/xxx/public-web/node_modules/enhanced-resolve/lib/Resolver.js:446:10)
    at Resolver.parse (/Users/xxx/public-web/node_modules/enhanced-resolve/lib/Resolver.js:430:25)
    at /Users/xxx/public-web/node_modules/enhanced-resolve/lib/ParsePlugin.js:33:29
    at _next0 (eval at create (/Users/xxx/public-web/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:8:1)
    at eval (eval at create (/Users/xxx/public-web/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:30:1)
    at /Users/xxx/public-web/node_modules/webpack/lib/cache/ResolverCachePlugin.js:199:17
    at Hook.eval [as callAsync] (eval at create (/Users/xxx/public-web/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
    at Resolver.doResolve (/Users/xxx/public-web/node_modules/enhanced-resolve/lib/Resolver.js:398:16)
    at doRealResolve (/Users/xxx/public-web/node_modules/webpack/lib/cache/ResolverCachePlugin.js:138:13)

Setting the webpack config config: false eliminates the error and the build runs normally.

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

I see directories being created under my working repo in the node_modules/.cache folder, but not on my problem repo. A .cache folder is created, but no webpack or webpack/client-development folders.

What is the expected behavior?

Cannot figure out why one repo is throwing this error and the other is not.

Other relevant information: webpack version: 5.0.0 Node.js version: 14.13.1 Operating System: MacOS Catalina 10.15.7 Additional tools:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 66 (33 by maintainers)

Commits related to this issue

Most upvoted comments

@egs33 big thanks, found the problem

Yes, I found bug, two problems:

  • bug in sass-loader
  • ugly error from webpack when you run:
const resolve = loaderContext.getResolve(options); 

resolve(context,  undefined);
// or resolve(undefined,  undefined)

WIP on first


I even can tell you why there is an error with node-sass and no problems with sass 😄

I’m seeing similar issues, and also have a .scss file containing:

@import "~bootstrap/scss/_functions.scss";
@import "~bootstrap/scss/_variables.scss";

I was getting the same error in my project. But, using sass package instead of node-sass solved the error. (for sass-loader)

@evilebottnawi yes, that shaved the non-cached run down from 14440 ms to 11523 ms, but cached run still around ~1650 ms. Still, thanks for the tip - appreciate it!

@evilebottnawi can confirm sass-loader 10.0.4 solves the issue I’ve had with the cache, webpack 5 feels rock solid now! 🎉

In my real project, compile time went from 14440 ms to 1667 ms using the filesystem cache. (on a threadripper/nvme m.2)

I’m really curious about the small change to bring the compile time even further down?

@joakimriedel Found how we can improve your build 😄 small change and your time will be webpack 5.2.0 compiled with 2 warnings in 168 ms 😄

Thanks I will look at this in near future, a lot of issues 😞

@gtwilliams03 no need, thanks for the issue

@gtwilliams03 Same problem, thanks!

This is the request coming in to ResolverCachePlugin.doResolve:

{
  _ResolverCachePluginCacheMiss: true,
  context: {},
  path: '/Users/xxx/public-web/src/routes/Admin',
  request: undefined
}

There shouldn’t be a undefined value there. Seems like something is passing undefined to resolve. Maybe you are able to track this down by inserting a if(!request) somewhere higher in the stack trace. Probably a loader via getResolve() or resolve (see NormalModule.js createLoaderContext.

@egs33 Thank you so much! I was trying to figure out how to break the project apart to come up with a reproducible repo… Much appreciated!