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
I am not sure if it's a correct place to ask this. I am also not sure if it's a bug, feature request or just question. Sorry if I am wrong. I don't think community can help me much here.
Let's suppose I have a page. The page can be rendered server-side or we can navigate to it from within the client. Suppose that there is a reason to do some extra work in case we render the page server-side using HTTP Request data. Suppose we don't need this work to be done on client-side page renders.
Now I also need this to be done in the getInitialProps hook. And I use fs module to get the work done. This is where the problem comes: trying to import fs module into a component leads to error: ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in ...
Next.js allows the same code to run on both client and server. However it seems it can't run server-specific modules even if it's on server.
Why is that so and how does one work around this?
There is another closed related question here: #4552
Should an API always be used in such cases? I think it might be redundant in some cases.
The text was updated successfully, but these errors were encountered:
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
vercel
locked as resolved and limited conversation to collaborators
Jan 31, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am not sure if it's a correct place to ask this. I am also not sure if it's a bug, feature request or just question. Sorry if I am wrong. I don't think community can help me much here.
Let's suppose I have a page. The page can be rendered server-side or we can navigate to it from within the client. Suppose that there is a reason to do some extra work in case we render the page server-side using HTTP Request data. Suppose we don't need this work to be done on client-side page renders.
Now I also need this to be done in the
getInitialProps
hook. And I usefs
module to get the work done. This is where the problem comes: trying to importfs
module into a component leads to error:ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in ...
Next.js allows the same code to run on both client and server. However it seems it can't run server-specific modules even if it's on server.
Why is that so and how does one work around this?
There is another closed related question here:
#4552
Should an API always be used in such cases? I think it might be redundant in some cases.
The text was updated successfully, but these errors were encountered: