Repository: next.js
Issue: Server stack traces don't match TypeScript source
Labels: bug

### Link to the code that reproduces this issue

https://github.com/CJEnright/nextjs-source-map

### To Reproduce

1. Start dev server
2. Go to `http://localhost:3000/api/test-pages`
3. Look for logged stack trace in console
4. Stack trace will mention irrelevant lines, for example:
```
Error
    at GET (webpack-internal:///(rsc)/./src/app/test-app/route.ts:8:17)
    at /Users/cj/Code/nextjs-source-map/node_modules/.pnpm/next@14.0.4-canary.14_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62629
	[...]
```
(The exception is created on line 4, not line 8)

Note that this also occurs in app dir, that same repro has a route demonstrating that: `http://localhost:3000/test-app`

### Current vs. Expected behavior

Currently the line number pointed to is the last line of the file, where no executable statements exist. I would expect the line numbers in the exception to match with the line numbers that originated the exception.

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
  Node: 18.16.0
  npm: 8.15.0
  Yarn: 1.22.19
  pnpm: 8.9.2
Relevant Packages:
  next: 14.0.4-canary.14
  eslint-config-next: 14.0.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.2
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

Not sure

### Additional context

The repro project is just a `create-next-app` with two routes: one in the pages dir and the other in app. Same result happens across both.


Some settings I've tried: 
* Setting `expirimental.serverSourceMaps = true`, same result
* Setting  `expirimental.serverSourceMaps = true` and webpack's `config.devtool = "eval-source-map"`, same result

When running this on vercel the output is less useful, with the reported error coming from:
```
at u (/var/task/.next/server/app/test-app/route.js:1:506)
```

If the route uses code splitting when deployed to vercel it doesn't even tell you which file had the issue, instead it just calls out the chunk in question:
```
at /var/task/apps/nextjs/.next/server/chunks/8393.js:3611:15
```

I _was_ able to get a useful output when deploying with the following setup:
* Setting  `expirimental.serverSourceMaps = true` and webpack's `config.devtool = "eval-source-map"` and installing `source-map-support` on the api routes

This yielded:
```
at u (/var/task/.next/server/app/test-app/webpack:/nextjs-source-map/src/app/test-app/route.ts:6:15)
```
Which is ugly, but works! What's unfortunate, though, is that this only works when deployed. When running the dev server this still points to a bad line number.


Related issues/discussions:
* https://github.com/vercel/next.js/discussions/21261
* https://github.com/vercel/next.js/issues/45825

I understand webpack compilation will change executed file contents, however I think it's very important that exceptions can be traced back to the human readable code that caused them, otherwise they're not very actionable. It would be very useful to have a known good config/setup that logs correct stack traces both in dev and when deployed. 

Thanks!