Fixes #31240: Adding a recursive addPackagePath function in webpack-config (#31264)
Fixes #31240: Adding a recursive addPackagePath function in webpack-config (#31264)



Fixes: https://github.com/vercel/next.js/issues/31240
Closes: https://github.com/vercel/next.js/pull/32324
Adding a try-catch block to handle situations when packages are found at relative path in getPackagePath function. This is likely to occur when using `preact` instead of `react-dom`, as `scheduler` package will not be found wrt `react-dom`

## Bug

- [x] Related issues linked using `fixes #31240`

Co-authored-by: JJ Kasper <fbae0e752deb2c0fed663fa6dec6c97ee2546cfe@users.noreply.github.com>
azukaru/next.js,JeromeFitz/next.js,JeromeFitz/next.js,azukaru/next.js,JeromeFitz/next.js,azukaru/next.js,JeromeFitz/next.js,azukaru/next.js