220v
젝무의 개발새발
220v
전체 방문자
오늘
어제
  • 분류 전체보기 (255)
    • AI (35)
      • ML, DL 학습 (30)
      • 논문 리뷰 (4)
      • 실습 및 프로젝트 (1)
    • Algorithm (145)
      • LeetCode (13)
      • 프로그래머스 (35)
      • 백준 (96)
      • 알고리즘, 문법 정리 (1)
    • Mobile, Application (17)
      • Flutter (10)
      • iOS, MacOS (7)
    • BackEnd (7)
      • Flask (1)
      • Node.js (5)
      • Spring, JSP..etc (1)
    • Web - FrontEnd (18)
      • JavaScript, JQuery, HTML, C.. (12)
      • React (6)
    • DataBase (1)
      • MySQL (1)
      • Firebase Firestore (0)
      • Supabase (0)
    • Git (1)
    • 기타 툴 및 오류 해결 (3)
    • 강의 (5)
      • Database (3)
      • 암호학 (2)
      • 알고리즘 (0)
    • 후기와 회고 (2)
    • 블로그 꾸미기 (1)
    • 일상과 이것저것 (20)
      • 맛집 (12)
      • 세상사는일 (4)
      • 도서리뷰 (1)
      • 이런저런 생각들 (잡글) (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • implementation
  • two pointer
  • BFS
  • bitmasking
  • dfs
  • 다익스트라
  • 백준
  • Mathematics
  • Priority Queue
  • binary search
  • 프로그래머스
  • 오블완
  • Backtracking
  • top-down
  • Greedy
  • topological sort
  • simulation
  • union-find
  • 티스토리챌린지
  • REACT
  • Prefix Sum
  • 구현
  • dp
  • disjoint set
  • Minimum Spanning Tree
  • 위상 정렬
  • Lis
  • IMPLEMENT
  • Dynamic Programming
  • brute-Force

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
220v

젝무의 개발새발

Web - FrontEnd/React

[React] React에서 dotenv 사용 시 오류. (Module not found: Error: Can't resolve 'fs' in '/Users/~/Desktop/React/~/node_modules/dotenv/lib')

2022. 5. 23. 11:27

React 프로젝트에서 dotenv로 환경변수를 관리해주려고 할 때 생겼던 오류.

.env파일은 루트 폴더 위치에, 환경변수를 사용하는 파일은 src 폴더 내에 존재할 때.

 

Error Message

ERROR in ./node_modules/dotenv/lib/main.js 1:11-24

Module not found: Error: Can't resolve 'fs' in '/Users/~/Desktop/React/~/node_modules/dotenv/lib'


ERROR in ./node_modules/dotenv/lib/main.js 3:13-28

Module not found: Error: Can't resolve 'path' in '/Users/~/Desktop/React/~/node_modules/dotenv/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }


ERROR in ./node_modules/dotenv/lib/main.js 5:11-24

Module not found: Error: Can't resolve 'os' in '/Users/~/Desktop/React/~/node_modules/dotenv/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
	- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "os": false }

 

해결

import dotenv from "dotenv" 
dotenv.config() 

비슷한 것들 다 지우면 된다.

 

create-react-app 으로 만든 react 프로젝트는... dotenv 가 내장되어 있단다.

역시 React 편하다;

 

Reference

db2dev.tistory.com/entry/React-Webpack으로-구축한-React-프로젝트에서-환경-변수env-사용하기

 

    'Web - FrontEnd/React' 카테고리의 다른 글
    • [React] XD 파일 React 페이지로 변환하기 (Fireblade 플러그인 사용)
    • [React] React와 Firebase Firestore 연동하여 CRUD 구현하기
    • [React] React에서 모바일, PC버전 각각 다른 페이지로 라우팅하기
    • [React] React 설치하기. (M1 Mac 환경에서 React 설치)
    220v
    220v
    DGU CSE 20 / Apple Developer Academy @ POSTECH 2nd Jr.Learner.

    티스토리툴바