Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build compilation warning "Node.js module is loaded ('url' at line 3)" when using middleware #57533

Closed
1 task done
frasergr opened this issue Oct 26, 2023 · 3 comments · Fixed by #57685
Closed
1 task done
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@frasergr
Copy link

Link to the code that reproduces this issue

https://github.com/frasergr/url-edge-warning-next14

To Reproduce

  1. npx create-next-app@latest
  2. Add middleware.ts (warning is present whether there is any code in the middleware() function or not)
  3. npm run build
  4. Observe warning

NOTE: subsequent builds will not show the warning but if you delete .next/ and build again it will show the warning

Current vs. Expected behavior

Results in an unexpected warning during build:

⚠ Compiled with warnings

./node_modules/.pnpm/next@14.0.0_@babel+core@7.22.6_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/esm/shared/lib/router/utils/app-paths.js
A Node.js module is loaded ('url' at line 3) which is not supported in the Edge Runtime.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 16:27:29 UTC 2
Binaries:
  Node: 18.17.1
  npm: 9.6.7
  Yarn: N/A
  pnpm: 8.6.12
Relevant Packages:
  next: 14.0.0
  eslint-config-next: 14.0.0
  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, Middleware / Edge (API routes, runtime)

Additional context

The warning appeared in next@13.5.7-canary.24

@frasergr frasergr added the bug Issue was opened via the bug report template. label Oct 26, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Oct 26, 2023
@ovflowd
Copy link

ovflowd commented Oct 26, 2023

The warning also appears on next 14.0.0

@AhmedBaset
Copy link
Contributor

It's started with the next@14

./node_modules/.pnpm/next@14.0.0_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/esm/shared/lib/router/utils/app-paths.js
A Node.js module is loaded ('url' at line 3) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

@kodiakhq kodiakhq bot closed this as completed in #57685 Oct 30, 2023
kodiakhq bot pushed a commit that referenced this issue Oct 30, 2023
### Fixing a bug

- Related issues linked using `fixes #57533`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### What?

If there is a `middleware.js` or `middleware.ts` file in Next.JS 14, running `next build` shows the following warning:

```
./node_modules/next/dist/esm/shared/lib/router/utils/app-paths.js
A Node.js module is loaded ('url' at line 3) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

Import trace for requested module:
./node_modules/next/dist/esm/shared/lib/router/utils/app-paths.js
```
This PR will remove the warning.

Closes NEXT-
Fixes #57533
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
3 participants