Next.js Discord

Discord Forum

A Node.js module is loaded ('fs' at line 1) which is not supported in the Edge Runtime.

Unanswered
Muscovy Duck posted this in #help-forum
Open in Discord
Avatar
Muscovy DuckOP
My code:
import fs from 'fs';
import path from 'path';
import { getRequestConfig } from 'next-intl/server';
import { routing } from './routing';
import { fetcher } from '../utils';

const isProd = process.env.NODE_ENV === 'production';

export default getRequestConfig(async ({ requestLocale }) => {
  // This typically corresponds to the `[locale]` segment
  let locale = await requestLocale;

  // Ensure that a valid locale is used
  if (!locale || !routing.locales.includes(locale)) locale = routing.defaultLocale;

  return {
    locale,
    messages: isProd
        ? JSON.parse(fs.readFileSync(path.join(process.cwd(), `public/translations/${locale}.json`), 'utf8'))
        : await fetcher('/app-translations', locale, { params: { lang: locale } }),
  };
});


how can i fix this problem

0 Replies