Repository: next.js
Issue: Problem loading WASM dependency with App Router
Labels: bug

### Link to the code that reproduces this issue or a replay of the bug

https://github.com/jmagan/minimal-wasm-next-app-router-problem

### To Reproduce

I was using the library @emurgo/cardano-serialization-lib-nodejs with the page directory. I tried to update my project to App Router and when I perform the following steps, I'm getting an error:

1. Install a WASM dependency, the dependency is yarn add @emurgo/cardano-serialization-lib-nodejs. (This is already done in the minimal example).
2. Run `yarn`and `yarn dev`
2. Navigate to http://localhost:3000/



### Current vs. Expected behavior

This error is thrown:

```
   Collecting page data ..Error: ENOENT: no such file or directory, open '/Users/user/ws/minimal-wasm-next-app-router-problem/.next/server/chunks/cardano_serialization_lib_bg.wasm'
    at Object.openSync (node:fs:603:3)
    at Object.readFileSync (node:fs:471:35)
    at 7831 (/Users/user/ws/minimal-wasm-next-app-router-problem/.next/server/chunks/831.js:2:308)
    at t (/Users/user/ws/minimal-wasm-next-app-router-problem/.next/server/webpack-runtime.js:1:142)
    at 3982 (//Users/user/ws/minimal-wasm-next-app-router-problem/.next/server/app/page.js:1:1838)
    at Function.t (/Users/user/ws/minimal-wasm-next-app-router-problem/.next/server/webpack-runtime.js:1:142)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async collectGenerateParams (/Users/user/ws/minimal-wasm-next-app-router-problem/node_modules/next/dist/build/utils.js:855:17) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/user/ws/Andamio/minimal-wasm-next-app-router-problem/.next/server/chunks/cardano_serialization_lib_bg.wasm'
}

> Build error occurred
Error: Failed to collect page data for /
    at /Users/user/ws/minimal-wasm-next-app-router-problem/node_modules/next/dist/build/utils.js:1191:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}

```

The name of the missing file is strange because it's supposed to be hashed and in this case, we've got: `.next/server/chunks/cardano_serialization_lib_bg.wasm`



### 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 22.6.0: Wed Jul  5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020
    Binaries:
      Node: 18.17.0
      npm: 9.6.7
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.19
      eslint-config-next: 13.4.19
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A
```


### Which area(s) are affected? (Select all that apply)

App Router

### Additional context

The problem would be that Webpack isn't detecting correctly the wasm dependency.

The `package.json`of the library @emurgo/cardano-serialization-lib-nodejs is:

```json
{
  "name": "@emurgo/cardano-serialization-lib-nodejs",
  "collaborators": [
    "EMURGO"
  ],
  "description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
  "version": "11.5.0",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Emurgo/cardano-serialization-lib.git"
  },
  "files": [
    "cardano_serialization_lib_bg.wasm",
    "cardano_serialization_lib.js",
    "cardano_serialization_lib.d.ts",
    "cardano_serialization_lib.js.flow"
  ],
  "main": "cardano_serialization_lib.js",
  "types": "cardano_serialization_lib.d.ts",
  "author": "EMURGO"
}
```

And this is the file structure:

```
.
├── LICENSE
├── README.md
├── cardano_serialization_lib.d.ts
├── cardano_serialization_lib.js
├── cardano_serialization_lib.js.flow
├── cardano_serialization_lib_bg.wasm
└── package.json
```

It seems that they used a tool called `wasm-bidgen`for compilling wasm from rust to javascript. This issue might affect other javascript packages compiled with the same tool.