question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware builds are using the package.json browser field

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Mar 16, 2022

Update, this behavior might change in the next canary release when this is published: https://github.com/vercel/next.js/pull/35335

0reactions
github-actions[bot]commented, Apr 16, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

browser vs module fields in package.json #4674 - GitHub
When module's package.json contains browser , module & main fields, webpack is bundling browser build by default.
Read more >
webpack/webpack - Gitter
Hi guys, I'm new to webpack, and I'm developing an npm chat package. ... I would like to send build progress to browser...
Read more >
The 'mode' option has not been set, webpack will fallback to ...
Field 'browser' doesn't contain a valid alias configuration using description file: /home/prithvi/Desktop/socialize/package.json (relative path: ...
Read more >
Create React App: A quick setup guide - LogRocket Blog
Our quick tutorial on Create React App covers how to set up a React app and configure some important features.
Read more >
Express/Node introduction - Learn web development | MDN
The node package manager (npm) provides access to hundreds of thousands of ... You can use Express middleware to add support for cookies, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found