Repository: storybook
Issue: [Bug]: Webpack 5 Compilation reads `node_modules` in Linux and crashes
Labels: bug,needs triage

### Describe the bug

We've recently switch to Storybook@7, in our local Mac machine works perfectly but our pipeline is broken with the following:

```
RangeError: Maximum call stack size exceeded
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at done (/root/project/node_modules/neo-async/async.js:777:13)
    at /root/project/node_modules/webpack/lib/ContextModuleFactory
    at Hook.eval [as callAsync] (eval at create (/root/project/nod
y.js:28:14), <anonymous>:18:1)
    at Array.<anonymous> (/root/project/node_modules/webpack/lib/C
    at runCallbacks (/root/project/node_modules/webpack/node_modul
ileSystem.js:18:17)
    at /root/project/node_modules/webpack/node_modules/enhanced-re
49:7
    at callback (/root/project/node_modules/graceful-fs/polyfills.
    at FSReqCallback.oncomplete (node:fs:196:5)
```

Although this is the error that I encounter in my project, to someone else building storybook might crash with the following:
```
FATAL ERROR: Reached heap limit Allocation failed
``` 

### To Reproduce

```
git clone git@github.com:M3kH/issue-storybook-webpack-5.git
cd issue-storybook-webpack-5
make storybook.build
```

### System

_No response_

### Additional context

I'm not 100% sure that this issue is Storybook issue, but is difficult to track it down and the only way that I can get to reproduce it is trough Storybook.

I run another instance of `webpack@5` in the same project and I'm not facing the same issue, so I think might be Storybook related.

For what I could have see the main issue relays on the how the modules gets resolved, in my projects calls inside the `ContextModuleFactory.resolveDependency` of `webpack` get different values depending on the systems that runs on.

In Mac OS:
```
 {
  resource: '/project',
  resourceQuery: '',
  resourceFragment: '',
  recursive: true,
  regExp: /^\.\/.*$/,
  include: /(?:component\.stories\.tsx)$/,
  exclude: null,
  referencedExports: null,
  category: 'esm',
  typePrefix: 'import()'
}
```

Where in Linux:
```
{
  resource: '/root/project',
  resourceQuery: '',
  resourceFragment: '',
  recursive: true,
  regExp: /^.*$/,
  include: undefined,
  exclude: undefined,
  referencedExports: undefined,
  category: 'commonjs',
  typePrefix: undefined
}
```

Beside the fact I can't explain why, depending on the system the `category` property can change.
The real issue is the fact that the property `include` is undefined making `webpack` scanning the entire `node_modules` and so depending of the size of the `node_modules` the process would eventually run out of memory or doing to many calls until exceeds the maximum allow call-stack.