codestates / codestates/rightnow

[Error Handling] react app에서 .env 불러오기 실패

Open
#148 0 comments 0 reactions 0 assignees View on GitHub
err-handling
Dominant language
TypeScript
Stars
0
Forks
3
PR merge metrics
No merged PRs in 30d

Description

### **어떤 에러인가요?**

- client(react app)에서 dotenv 모듈을 설치하고 require('dotenv').config()를 통해 .env 변수를 불러오려고 했지만 되지 않았습니다.

### **에러 메시지**

```
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 }
```

### **에러 핸들링 방법**

- 해결하기 위해서 검색을 해 본 결과 react app에는 자체적으로 dotenv모듈이 내장되어 있다고 한다.
- 따라서 import를 하거나 require를 통해 불러온 dotenv를 삭제하니 문제가 해결되었다.

### **에러 핸들링을 위해 참고한 레퍼런스 링크**

[링크](https://velog.io/@godkor200/react-dotenv-%EC%98%A4%EB%A5%98)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.