[Next.js] Module not found: Can't resolve 'fs'

Pulan·2022년 9월 20일
1

블로그 이동

fs 모듈은 node.js에서 컴퓨터의 파일 시스템에 접근하여 읽고 사용하기 위한 모듈이다.
그래서 클라이언트에서 fs 모듈을 사용할려고하면 Module not found: Can't resolve 'fs'와 같은 에러 표시가 발생하게 된다.
이 문제를 해결하기 위해서는 웹펙을 설정하면 해결이 된다.

next.config.js 파일


/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
};

module.exports = nextConfig;

수정 후

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,

  webpack: (config, { isServer }) => {
    if (!isServer) {![](https://velog.velcdn.com/images/plu457/post/09679aca-3436-447a-bd0e-395177fa784b/image.png)

      config.resolve.fallback = {
        fs: false,
      };
    }

    return config;
  },
};

module.exports = nextConfig;
profile
현재 개발 중인 블로그로 내용들을 개선하면서 업데이트하고 있습니다. https://www.plu457.life/

0개의 댓글