-
Module not found: Can't resolve 'fs'
i have got the same issue with webpack too, but i fixed that by using the following next config const nextConfig: NextConfig = {
webpack: (config, { isServer }) => {
if (isServer) {
return config;
}
config.resolve.fallback = { fs: false, net: false } // don't try to import this on the client
return config;
}
}
how can we tell turbopack to do exact same thing ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
So like, here the issue is that you got away with it on webpack. Away with what? Importing server side code into the client. I know that, often this can be out of your control, you need a util, or whatever from a library out of your control, and simply importing it into your client code, indirectly imports Anyway, you can try this: import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
turbopack: {
resolveAlias: {
'fs': {
browser: './src/lib/empty.ts'
}
}
}
};
export default nextConfig; Then I have a
Docs source: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#resolving-aliases |
Beta Was this translation helpful? Give feedback.
-
it worked thanks @icyJoseph |
Beta Was this translation helpful? Give feedback.
-
Turbopack currently doesn’t support resolve.fallback the same way Webpack does — so you can’t directly tell it to replace Node core modules like fs, net, or path with false yet. The reason is that Turbopack doesn’t polyfill Node.js built-ins for the client bundle at all. It expects client-side code not to import server-only modules. In other words, while Webpack lets you “silence” imports like fs with:
Turbopack’s model is stricter: if a client bundle references a Node-only module, it will error. ✅ Workarounds: Use dynamic imports guarded by runtime checks:
Move the logic into a Server Component or a server-only utility (server/ folder). Temporarily disable Turbopack and build with Webpack if you rely on polyfills until feature parity improves. 🧭 Status: |
Beta Was this translation helpful? Give feedback.
So like, here the issue is that you got away with it on webpack. Away with what? Importing server side code into the client.
I know that, often this can be out of your control, you need a util, or whatever from a library out of your control, and simply importing it into your client code, indirectly imports
fs
or any other Node.js module, but it is important to try and keep these separate.Anyway, you can try this:
Then I have a
src/lib/empty.ts
file (I am…