You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Module not found: Can't resolve 'querystring'
Import trace for requested module:
./node_modules/.pnpm/node-fetch@2.6.7/node_modules/node-fetch/lib/index.mjs
./node_modules/.pnpm/isomorphic-fetch@3.0.0/node_modules/isomorphic-fetch/fetch-npm-node.js
./pages/_middleware.js
https://nextjs.org/docs/messages/module-not-found
You're using a Node.js module (querystring) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
I know that we have access to fetch inside middlewares, but the question I want to ask is how can one write a module that works on both Node.js and edge-runtimes without making the users to manually specify the file to import?
Expected Behavior
I expect Next.js to by default import browser field of package.json inside middlewares. Or don't check for native modules inside conditions that are not true on middlewares. For example in this one:
import{NextResponse}from'next/server'letcryptoif(process?.versions?.node){console.log('is Node')// uncommenting below line throws error: You're using a Node.js module (crypto) which is not supported in the Edge Runtime.// crypto = require('crypto').webcrypto // or maybe @peculiar/webcrypto}else{console.log('not Node')// this gets printed on terminalcrypto=global?.crypto||window?.crypto// and some other fallbacks}exportconstmiddleware=async(req,ev)=>NextResponse.next()
EDIT:
I understand the reasoning behind not importing browser field as mentioned at #36844 (comment). But for the second one (selective requiring/import), I think that's a bug.
The text was updated successfully, but these errors were encountered:
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.
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Put something like this in
pages/_middleware.js
:It throws error like:
I know that we have access to
fetch
inside middlewares, but the question I want to ask is how can one write a module that works on both Node.js and edge-runtimes without making the users to manually specify the file to import?Expected Behavior
I expect Next.js to by default import
browser
field of package.json inside middlewares. Or don't check for native modules inside conditions that are not true on middlewares. For example in this one:EDIT:
I understand the reasoning behind not importing browser field as mentioned at #36844 (comment). But for the second one (selective requiring/import), I think that's a bug.
The text was updated successfully, but these errors were encountered: