Module not found Can't resolve 'fs'

I am running into this error:
Module not found: Can't resolve 'fs'
> 1 | const fs = require("fs")
Module not found: Can't resolve 'fs'
> 1 | const fs = require("fs")
I read that it can be fixed like so in next.config:
module.exports = {
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}

return config
}
}
module.exports = {
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}

return config
}
}
Being the noob that I am, I don't know how to translate into the next.config in the t3 stack (next.config.mjs):
// @ts-check
import { env } from "./src/env/server.mjs";

/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
*
* @template {import('next').NextConfig} T
* @param {T} config - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return config;
}

export default defineNextConfig({
reactStrictMode: true,
swcMinify: true,
// Next.js i18n docs: https://nextjs.org/docs/advanced-features/i18n-routing
i18n: {
locales: ["en"],
defaultLocale: "en",
},
});
// @ts-check
import { env } from "./src/env/server.mjs";

/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
*
* @template {import('next').NextConfig} T
* @param {T} config - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return config;
}

export default defineNextConfig({
reactStrictMode: true,
swcMinify: true,
// Next.js i18n docs: https://nextjs.org/docs/advanced-features/i18n-routing
i18n: {
locales: ["en"],
defaultLocale: "en",
},
});
? Tried to do this, but didn't work:
function defineNextConfig(config) {
if (!isServer) {
config.node = {
fs: 'empty'
}
}
return config;
}
function defineNextConfig(config) {
if (!isServer) {
config.node = {
fs: 'empty'
}
}
return config;
}
1 Reply
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server