dotenv를 사용할 일이 있어 서버에서와 같은 방식으로 dotenv를 설치하고 
사용하려는데 에러발생 
ERROR in ./node_modules/dotenv/lib/main.js 1:11-24

Module not found: Error: Can't resolve 'fs' in '/Users/user/Documents/projects/react/goback/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/user/Documents/projects/react/goback/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 }

REACT_APP을 붙여야한다는 글을 보고 따라해봤는데도 그대로 였다 

REACT_APP을 안붙인게 이유였다면 dotenv를 불러오는데 에러가 나지는 않지... 

 

이유는 간단했다 

create-react-app으로 프로젝트를 생성하면 dotenv가 내장되어 있기 때문에 에러가 발생했던 것이었고

import했던 dotenv를 지우 package를 삭제하니 정상적으로 불러와진다 

반응형

'Front' 카테고리의 다른 글

[React] npm eject 되돌리기  (0) 2022.04.09

+ Recent posts