-
-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.0.0-beta.4] Module not found: Can't resolve 'fs' #935
Comments
Hi @kdelmonte – this is most likely because you have imported |
Thank you @isaachinman , I am only using it inside
Please advise. |
@kdelmonte You'll need to provide a reproducible repo. |
@isaachinman I found this issue. I was exporting |
I have same issue, in 8.0.0-beta.4, but I did all the imports correctly and I totally tried to do it like in read.me file and example from the repository
_app.tsx import { appWithTranslation } from "next-i18next";
import { AppProps } from "next/app";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const MainLayout = (Component as any).MainLayout || DefaultLayout;
const NestedLayout = (Component as any).NestedLayout || DefaultLayout;
return (
<>
/.../
<MainLayout>
<NestedLayout>
<Component {...pageProps} />
</NestedLayout>
</MainLayout>
/.../
</>
);
};
const DefaultLayout: React.FC = ({ children }) => <>{children}</>;
export default appWithTranslation(App); file where i use serverSideTranslations: import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { GetStaticProps } from "next";
import Grid from "@material-ui/core/Grid";
import { Header } from "../components/Header";
const AppLayout: React.FC = ({ children }) => (
<>
<Grid container direction="column" alignItems="center">
<Header />
{children}
</Grid>
</>
);
export const getStaticProps: GetStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale, ["translation"])),
},
});
export default AppLayout; file where i use useTranslation import { useTranslation } from "next-i18next";
import { NavLink } from "../../../../components/NavLink";
export const Header = () => {
const { t } = useTranslation();
return (
/ .../
<NavLink title={t("something1")} href="/#" />
<NavLink title={t("something2")} href="/#" />
<NavLink title={t("something3")} href="/#" />
/ .../
);
}; next-18next-config.js import { initReactI18next } from "react-i18next";
const path = require("path");
module.exports = {
defaultLocale: "en",
locales: ["en", "ru"],
localePath: path.resolve("./public/translations"),
use: [initReactI18next], // this line did not affect the error in any way
debug: true,
}; next.config.js module.exports = {
images: {
domains: ["..."],
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
issuer: {
test: /\.(js|ts)x?$/,
},
use: ["@svgr/webpack"],
});
return config;
},
async redirects() {
return [
{
source: "/",
destination: "/...",
permanent: false,
},
];
},
i18n: {
defaultLocale: "en",
locales: ["en", "ru"],
},
}; |
I'm resolve this issues, this code export const getStaticProps: GetStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale, ["translation"])),
},
}); must be in |
This is exactly what happened to me. Beware, future readers. |
Just want to note that this is a general NextJs "gotcha", and isn't necessarily specific to |
@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
I could solve it for now with importing // import { useTranslation } from 'next-i18next' // => throws error
import { useTranslation, UseTranslationOptions, UseTranslationResponse } from 'react-i18next'
type TranslationNamespace = 'common'
const useLmTranslation = (
ns?: TranslationNamespace,
options?: UseTranslationOptions
): UseTranslationResponse<string> =>
useTranslation((ns as string) ?? 'common', options)
export default useLmTranslation EDIT: webpackFinal: async (config, {configType}) => {
config.resolve.alias = {
...config.resolve.alias,
'next-i18next': 'react-i18next'
}
return config
} |
Hey @dohomi – hopefully we can solve this together. As a package, Strange that The swap from |
@isaachinman, sound OK, I will prepare a PR |
Fixed by #974. |
@isaachinman @felixmosh I updated to 8.0.1 and the error still exists and Storybook is not building:
I'm only using the |
Do you use webpack 5 in you storybook build? |
Putting this in my /storybook/.main.js solved it for me, cheers |
This solved it for me |
What to do if I need to use it in components folder? |
you can still use the useTranslation hook in components |
Thank you, I figured out 😅 |
@dohomi Did you figure out a workaround other than the alias to Webpack config?
|
The root cause of this issue in storybook is related to this line. In Webpack 5 there is no default polyfill for You have 2 choices to solve the issue:
//webpack.config.js
webpackFinal: async (config, { configType }) => {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false, // <------
path: false // <-----
};
return config;
};
webpackFinal: async (config, { configType }) => {
config.resolve.fallback = {
...config.resolve.fallback,
fs: require.resolve("browserify-fs"), // <------
path: require.resolve("path-browserify"), // <------
};
return config;
}; |
@felixmosh Think we'd be better off relying directly on |
@isaachinman I'm not sure I got the idea, The "problem" is that the code is isomorphic, and contains code of server side, |
|
import of what? |
@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? |
nextjs 12.2 add Edge SSR(https://nextjs.org/blog/next-12-2#edge-server-rendering-experimental) feature, it can also cause this issue. |
I'm using |
Сan anyone explain how to solve the problem using components outside of pages? |
In my case, that was the use of
Replace all the occurences with fixes the problem.
As a side note, importing
|
Hey, I'm trying to get my head around the internationalization stuff but running into this 'Can't resolve fs' error. I'm using Next.js 13 and with the app routing option. Has anyone managed to find a fix/work around for this? |
Create a i18n.js file in the root of your project with the following content: const NextI18Next = require('next-i18next').default;
module.exports = new NextI18Next({
defaultLanguage: 'en',
otherLanguages: ['fr'], // Add your supported languages here
localeSubpaths: {},
localePath: typeof window !== 'undefined' ? 'public/locales' : 'locales',
}); |
I personally identified that dependencies
With this configuration I managed to bypass the explicit use of common. I will implicitly have the specific translation that I require and common. |
Hello @ivnmood But I want to use it in the components folder because I'm using the navbar as a component.
|
Describe the bug
Getting the following error when running the app:
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
The text was updated successfully, but these errors were encountered: