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

Middleware builds are using the package.json browser field #35370

Closed
1 task done
tatethurston opened this issue Mar 16, 2022 · 6 comments
Closed
1 task done

Middleware builds are using the package.json browser field #35370

tatethurston opened this issue Mar 16, 2022 · 6 comments
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware

Comments

@tatethurston
Copy link

Verify canary release

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

Provide environment information

(not relevant)

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64
Binaries:
  Node: 16.14.0
  npm: 8.3.1
  Yarn: 1.22.17
  pnpm: N/A
Relevant packages:
  next: 12.1.0
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

Describe the Bug

Middleware webpack builds are using the "browser" field from package.json, which is surprising because middleware only run s in a server context.

With the following in your package.json:

  "browser": {
    "some-package": false,
  }

some-package will not be defined in middleware handlers.

Expected Behavior

The "browser" field from package.json is not used when building middleware code paths.

To Reproduce

  1. Add a package entry within the browser field in the project package.json, setting it's value to false
  2. Import the package into middleware
  3. Observe the package is undefined in the middleware runtime
@tatethurston tatethurston added the bug Issue was opened via the bug report template. label Mar 16, 2022
@tatethurston
Copy link
Author

@balazsorban44
Copy link
Member

This is expected, as Middleware uses the Edge Runtime (which builds on the same web standard APIs as browsers), not Node.js. https://nextjs.org/docs/api-reference/edge-runtime#unsupported-apis.

@balazsorban44 balazsorban44 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2022
@balazsorban44 balazsorban44 added the Middleware Related to Next.js Middleware label Mar 16, 2022
@balazsorban44
Copy link
Member

Update, this behavior might change in the next canary release when this is published: #35335

@tatethurston
Copy link
Author

@balazsorban44 The linked article cites middleware runtime constraints, but nothing about how dependencies are built. As a user this overloading of the browser field is surprising -- I would not expect to have the browser field applied to a build that is not executed on the client's browser. User's may want to consume a different library entry point or ensure it doesn't end up in client builds irrespective of any runtime constraints.

@balazsorban44
Copy link
Member

I forwarded your feedback, thank you!

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. 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 Apr 16, 2022
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. Middleware Related to Next.js Middleware
Projects
None yet
Development

No branches or pull requests

2 participants