next-i18next: [8.0.0-beta.4] Module not found: Can't resolve 'fs'
Describe the bug
Getting the following error when running the app:
wait - compiling...
error - ./node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:28:0
Module not found: Can't resolve 'fs'
Occurs in next-i18next version
8.0.0-beta.4
Steps to reproduce
You must provide a reproducible repository, or copy/paste blocks of code which are sufficient to reproduce the bug.
Expected behaviour
You must provide a clear and concise description of what you expected to happen.
Screenshots
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 36 (13 by maintainers)
Commits related to this issue
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
- storybook 빌드 에러 해결 참고: https://github.com/i18next/next-i18next/issues/935#issuecomment-802001105 — committed to titicacadev/triple-frontend by jaehyeon48 2 years ago
I’m resolve this issues, this code
must be in
pages
folder, but i’m use it incomponents
folderPutting this in my /storybook/.main.js solved it for me, cheers
@isaachinman I found this issue. I was exporting
getServerSideProps
from another file into the Next.js page file. MovinggetServerSideProps
directly to the page file fixed this issue. Thanks.Hi @kdelmonte – this is most likely because you have imported
serverSideTranslations
in some place where client side code is being run. It can only be used in server side data fetching methods such asgetStaticProps
andgetServerSideProps
. Hope that helps!@isaachinman I am using NextJS and Storybook together and I did not share any code SSR related code within both separate builds.
I still realise when I use the
useTranslation
hook in the Storybook environment I receive the error:I could solve it for now with importing
useTranslation
fromreact-118next
instead ofnext-i18next
- I am not sure if thats the right way to do this.EDIT: I add an alias to point via Webpack config to different alias to solve the error for now.
The root cause of this issue in storybook is related to this line.
In Webpack 5 there is no default polyfill for
fs
&path
.You have 2 choices to solve the issue:
fs
bybrowserify-fs
import
of whatever we are currently usingfs
to achieve. Dynamic imports on the server side should be possible.This is exactly what happened to me. Beware, future readers.
Thank you @isaachinman , I am only using it inside
getServerSideProps
:Please advise.
In my case, that was the use of
Replace all the occurences with fixes the problem.
As a side note, importing
serverSideTranslations
as an util works fine for menextjs 12.2 add Edge SSR(https://nextjs.org/blog/next-12-2#edge-server-rendering-experimental) feature, it can also cause this issue.
you can still use the useTranslation hook in components
Just want to note that this is a general NextJs “gotcha”, and isn’t necessarily specific to
next-i18next
. It’s to do with how chunks are separated by webpack, despite there being client and server code in the same files (pages).@dohomi Did you figure out a workaround other than the alias to Webpack config?
Hi!
when I follow this approach to get this work in storybook then I start getting this errors
I bet this is because storybook is running in the same folder as the next.js app, and is loading I dont know why a file with that import.
Anybody has faced the same issue?
import of what?
@felixmosh Think we’d be better off relying directly on
import
at this point?What to do if I need to use it in components folder?
@isaachinman, sound OK, I will prepare a PR