Closed MuhammadSawalhy closed 4 months ago
I also read esm-package.md and couldn't resolve the issue after adding "type": "module"
in package.json.
OK, sorry for the inconvenience! This happens because I used indirectly the fs
module in Node.js in Edge runtime of Next.js exactly in middleware.ts
. Edge runtime doesn't support many of the Node modules and has some limitations to achieve other goals like performance and low latency.
I hope this comment will help someone in the future.
This error appeared for the first time to me while developing a Next.js@14 application. I suspected that it is due to experimental turbo bundler but after disabling it the same problem happened.
My environment:
20.10.0
14.1.0
7.0.1
Additional notes
I included
import "server-only";
at the top of ./lib/db.ts file to make sure that it runs in the server. And ./actions/users.ts has"use server";
directive at the top.