Repository: next.js
Issue: Missing webpack dependency when using output standalone + custom server
Labels: bug,Output (export/standalone)

### Link to the code that reproduces this issue

https://github.com/maximelebastard/nextjs-issue-custom-server

### To Reproduce

The issue is related to using the output: "standalone" with a custom server. See example repository.

1. Clone the reproducing repository
2. Run `npm install` then `npm run build` and `npm run start`
3. When starting the app, an error will be triggered due to a missing webpack file on a webpack require (see the error below)
4. To see the code triggering this issue, see this commit: https://github.com/maximelebastard/nextjs-issue-custom-server/commit/c47de3a03c6694ac760b748ed2fecc28b97bb2e5


### Current vs. Expected behavior

Expected:
1. I create a recent NextJS project (14.1.4) using a recent Node version (v20.12)
2. I want to deploy my app using Docker, therefore I use [the `output: "standalone"` configuration in `next.config.js`](https://nextjs.org/docs/pages/api-reference/next-config-js/output)
3. I want to use some logging middlewares, therefore I use [a custom `server.js`](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server)
5. When I run `npm run build` and copy my custom server code to the build dir, the app is properly built and the file is properly copied
6. When requiring next from `server.js`, all the dependencies are present and the server starts

Actual:
1. 1-4 are the same as expected
5. `.next/standalone/node_modules/next/dist/compiled/webpack/build5.js` does not exists in the built app
7. When requiring next from `server.js`, I'm getting the error below because webpack tries to require `build5.js`

```
> node .next/standalone/custom-server.js

node:internal/modules/cjs/loader:1143
  const err = new Error(message);
              ^

Error: Cannot find module './bundle5'
Require stack:
- /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/compiled/webpack/webpack.js
- /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config-utils.js
- /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config.js
- /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/next.js
- /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/custom-server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at /Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/require-hook.js:55:36
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at mod.require (/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:179:18)
    at exports.init (/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/compiled/webpack/webpack.js:24:28)
    at loadWebpackHook (/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config-utils.js:18:5)
    at loadConfig (/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config.js:642:46)
    at initialize (/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/lib/router-server.js:55:46) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/compiled/webpack/webpack.js',
    '/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config-utils.js',
    '/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/config.js',
    '/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/node_modules/next/dist/server/next.js',
    '/Users/maxime/workspace/issue-bundle5-nextjs/.next/standalone/custom-server.js'
  ]
}
```

### Provide environment information

```bash
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: standalone
```


### Which area(s) are affected? (Select all that apply)

Standalone mode (output: "standalone")

### Which stage(s) are affected? (Select all that apply)

next start (local)

### Additional context

A workaround I found is to disable standalone output.
That probably disables tree shaking and relies on the complete node_modules directory.
A big drawback is that it makes a heavy docker image.