title: Why am I getting this error when using Next.js middleware?
body: <h2>The Problem</h2>
  <p>I'm using Next.js, Prisma, and NextAuth's Email Provider strategy to setup an authentication system. I want to use Next.js middleware to redirect a request if it doesn't contain a valid session. But any use of the middleware, like literally just having a function declared in the middleware.js file, throws this error:</p>
  <pre><code>error - (middleware)/node_modules/oidc-token-hash/lib/shake256.js (3:0) @ &lt;unknown&gt;
  error - Cannot read properties of undefined (reading 'substr')
  null
  </code></pre>
  <p>It logs this error about 5 times. This is the <code>middleware.js</code> file at <code>{root}/middleware.js</code></p>
  <pre><code>import { NextResponse } from 'next/server';
  
  export default function middleware(request) {
    return NextResponse.next();
  }
  </code></pre>
  <p>And here is this the <code>node_modules/oidc-token-hash/lib/shake256.js</code> file specified in the error:</p>
  <pre><code>const crypto = require('crypto');
  
  const [major, minor] = process.version.substr(1).split('.').map((x) =&gt; parseInt(x, 10));
  const xofOutputLength = major &gt; 12 || (major === 12 &amp;&amp; minor &gt;= 8);
  const shake256 = xofOutputLength &amp;&amp; crypto.getHashes().includes('shake256');
  
  module.exports = shake256;
  </code></pre>
  <p>Prior to creating this file, the app worked perfectly. I could authentiate via an email link, make simple GET requests to API routes, and do any other functionality. I've never seen this error before. The closest I can guess is that I have some sort of dependency/versioning issue, but I'm using damn near latest versions of Next, React, Prisma, NextAuth, Node, etc.</p>
  <p>Perhaps it's worth noting that I'm using React Query? Other than that I have no idea what might be causing this.</p>
  <p>Package.json:</p>
  <pre><code>{
    &quot;name&quot;: &quot;nextjs-starter-auth-sql&quot;,
    &quot;version&quot;: &quot;0.1.0&quot;,
    &quot;private&quot;: true,
    &quot;scripts&quot;: {
      &quot;dev&quot;: &quot;next dev&quot;,
      &quot;build&quot;: &quot;next build&quot;,
      &quot;start&quot;: &quot;next start&quot;,
      &quot;lint&quot;: &quot;next lint&quot;
    },
    &quot;dependencies&quot;: {
      &quot;@next-auth/prisma-adapter&quot;: &quot;^1.0.4&quot;,
      &quot;@prisma/client&quot;: &quot;^4.3.0&quot;,
      &quot;bcrypt&quot;: &quot;^5.0.1&quot;,
      &quot;next&quot;: &quot;12.2.5&quot;,
      &quot;next-auth&quot;: &quot;^4.10.3&quot;,
      &quot;nodemailer&quot;: &quot;^6.7.8&quot;,
      &quot;prop-types&quot;: &quot;^15.8.1&quot;,
      &quot;react&quot;: &quot;18.2.0&quot;,
      &quot;react-dom&quot;: &quot;18.2.0&quot;,
      &quot;react-query&quot;: &quot;^3.39.2&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;autoprefixer&quot;: &quot;^10.4.8&quot;,
      &quot;eslint&quot;: &quot;^8.23.0&quot;,
      &quot;eslint-config-airbnb&quot;: &quot;^19.0.4&quot;,
      &quot;eslint-config-next&quot;: &quot;12.2.5&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.26.0&quot;,
      &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.6.1&quot;,
      &quot;eslint-plugin-react&quot;: &quot;^7.31.1&quot;,
      &quot;eslint-plugin-react-hooks&quot;: &quot;^4.6.0&quot;,
      &quot;postcss&quot;: &quot;^8.4.16&quot;,
      &quot;prisma&quot;: &quot;^4.3.0&quot;,
      &quot;tailwindcss&quot;: &quot;^3.1.8&quot;
    }
  }
  
  </code></pre>
  <p>Happy to answer any questions you may have. Your help is truly appreciated.</p>