create-react-app dotenv 오류 ERROR in ./node_modules/dotenv/lib/main.js

연쇄코딩마·2021년 12월 31일

오늘 오류

Compiled with problems:X

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

Module not found: Error: Can't resolve 'fs' in '/Users/yubyeong-gug/Desktop/product_server_admin_client/product_server_admin_client/node_modules/dotenv/lib'


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

Module not found: Error: Can't resolve 'path' in '/Users/yubyeong-gug/Desktop/product_server_admin_client/product_server_admin_client/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 28:11-24

Module not found: Error: Can't resolve 'os' in '/Users/yubyeong-gug/Desktop/product_server_admin_client/product_server_admin_client/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 }

무지에서 온 삽질

백엔드를 주력으로 하는 나로서는 create-react-app로 생성된 react의 앱에 dotenv가 기본 내장되어 있는지도 몰랐다.

해결 방법

코드 최상단에

import dotenv from "dotenv" 
dotenv.config() 

이런거 지워 버리면 된다.

참고 : https://db2dev.tistory.com/entry/React-Webpack%EC%9C%BC%EB%A1%9C-%EA%B5%AC%EC%B6%95%ED%95%9C-React-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8%EC%97%90%EC%84%9C-%ED%99%98%EA%B2%BD-%EB%B3%80%EC%88%98env-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

감사합니다. 🙏

profile
只要功夫深,铁杵磨成针, 하고자 하면 쇠 막대기도 바늘로 만들 수 있다

4개의 댓글

comment-user-thumbnail
2022년 1월 6일

엥? 기본으로 있었던건가요...저도 한참 찾다가 몰랐네요...

1개의 답글
comment-user-thumbnail
2022년 10월 9일

삽질하다가 구원받고 갑니다

1개의 답글