Repository: next.js
Issue: [NEXT-648] Edge API route fails to build with an error "Module build failed: UnhandledSchemeError"
Labels: bug,linear: next

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT Tue Feb 14 19:45:58 UTC 2023
Binaries:
  Node: 18.14.0
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 7.27.0
Relevant packages:
  next: 13.2.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
```

### Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

### Link to the code that reproduces this issue

https://github.com/pajecawav/next-ofetch-edge-api-route

### To Reproduce

Clone repo and install packages:

```sh
git clone https://github.com/pajecawav/next-ofetch-edge-api-route
cd next-ofetch-edge-api-route
pnpm install
```

 Then `pnpm build` fails with the following error:

```
> next-ofetch-edge-api-route@ build /home/user/next-ofetch-edge-api-route
> next build

info  - Linting and checking validity of types...
info  - Creating an optimized production build...
Failed to compile.

node:buffer
Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395974
    at Hook.eval [as callAsync] (eval at create (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
    at Object.processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395899)
    at processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395761)
    at NormalModule.build (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:397789)
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:81243
    at NormalModule.needBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:401868)

Import trace for requested module:
node:buffer
./node_modules/.pnpm/node-fetch-native@1.0.2/node_modules/node-fetch-native/dist/index.mjs
./node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/node.mjs

node:fs
Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395974
    at Hook.eval [as callAsync] (eval at create (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
    at Object.processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395899)
    at processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395761)
    at NormalModule.build (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:397789)
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:81243
    at NormalModule.needBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:401868)

Import trace for requested module:
node:fs
./node_modules/.pnpm/node-fetch-native@1.0.2/node_modules/node-fetch-native/dist/index.mjs
./node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/node.mjs

node:https
Module build failed: UnhandledSchemeError: Reading from "node:https" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395974
    at Hook.eval [as callAsync] (eval at create (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
    at Object.processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395899)
    at processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395761)
    at NormalModule.build (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:397789)
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:81243
    at NormalModule.needBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:401868)

Import trace for requested module:
node:https
./node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/node.mjs

node:http
Module build failed: UnhandledSchemeError: Reading from "node:http" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395974
    at Hook.eval [as callAsync] (eval at create (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:25925)
    at Object.processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395899)
    at processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395761)
    at NormalModule.build (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:397789)
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:81243

Import trace for requested module:
node:http
./node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/node.mjs

node:net
Module build failed: UnhandledSchemeError: Reading from "node:net" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395974
    at Hook.eval [as callAsync] (eval at create (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
    at Object.processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395899)
    at processResource (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
    at iteratePitchingLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
    at runLoaders (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
    at NormalModule._doBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:395761)
    at NormalModule.build (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:397789)
    at /home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:81243
    at NormalModule.needBuild (/home/user/next-ofetch-edge-api-route/node_modules/.pnpm/next@13.2.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/webpack/bundle5.js:28:401868)

Import trace for requested module:
node:net
./node_modules/.pnpm/node-fetch-native@1.0.2/node_modules/node-fetch-native/dist/index.mjs
./node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/node.mjs


> Build failed because of webpack errors
 ELIFECYCLE  Command failed with exit code 1.
```

### Describe the Bug

I'm using `$fetch` function from [ofetch](https://github.com/unjs/ofetch) inside Edge API route handler and starting from `next@13.2.0` my build fails with an error `Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).`.

Downgrading to `next@13.1.6` fixes the issue.

Edge API route handler from reproduction repo:

```js
// src/pages/api/hello.js
import { $fetch } from "ofetch";

export const config = {
	runtime: "edge",
};

export default function handler() {
	$fetch();
	return new Response("foobar");
}
```

### Expected Behavior

Build finishes without errors.

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

_No response_

<sub>[NEXT-648](https://linear.app/vercel/issue/NEXT-648/edge-api-route-fails-to-build-with-an-error-module-build-failed)</sub>