Skip to content

When trying to import 'fs' I get the error: "Module not found: Can't resolve 'fs'" #54176

Answered by icyJoseph
ArturKazuo asked this question in Help
Discussion options

You must be logged in to vote

Hi,

When you use the fs module, you are banking on that API being present on the environment where your code runs.

When you use the use client directive, you are telling the framework to bundle the code for the component to be used in the browser.

There's a problem when combining those, because fs doesn't exist in the browser.

You have to refactor your code. So that the module that uses fs is not mixed with the module that is use client.

It was often the case that developers kept everything into one file, creating 1000+ lines files that mixed imports and relied on bundlers to be smart enough to figure out what to discard.

With RSC that's a bit more nuanced. Because 'use client' modules ar…

Replies: 8 comments 13 replies

Comment options

You must be logged in to vote
1 reply
@icyJoseph
Comment options

Answer selected by ArturKazuo
Comment options

You must be logged in to vote
2 replies
@icyJoseph
Comment options

@ArturKazuo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
10 replies
@AssiaChemlali
Comment options

@Shanmukhsvstp
Comment options

@AssiaChemlali
Comment options

@Shanmukhsvstp
Comment options

@AssiaChemlali
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
bug Issue was opened via the bug report template.
9 participants
Converted from issue

This discussion was converted from issue #54175 on August 17, 2023 13:50.