next.js: Module not found: Cant resolve fs
I’m trying to convert one of my components into a client component but I keep running into the “Module not found : Can’t resolve ‘fs’” error. I’ve found this to be useful but this component uses useState, therefore it has to be a client component, here is the relevant part of my code:
“use client”;
const Nav = () => { const [navOpen, toggle a Open] = useState(false);
return () }
Hi,
You are putting a "use client"
directive inside a server component. When the compiler tries to bundle that up for the client it touches fs
.
Remove that "use client"
directive and you’ll be fine.
To format code it is better to use triple `:
like this: ```js
and then put your code
And then close with triple ` once again:
like this: ```
So that it can look like:
let world = "world"
const hello = `${world}`
_Originally posted by @icyJoseph in https://github.com/vercel/next.js/discussions/45784#discussioncomment-4938892_
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 16 (8 by maintainers)
@zinzombe-kin if that’s the case then either turn this into a discussion and mark it as answered by my comment, or just close the issue (simplest and fastest).
Have a great day and don’t hesitate to ask further, preferably first as a discussion.
Thanks a lot! This has fixed my issue and it’s working fine now!