criei um app usando npx-create-react-app e depois baixei o modulo dotenv para usar variáveis de ambiente, mas na hora de compilar o webpack está dando o erro:
Module not found: Error: Can't resolve 'fs' in 'C:\{caminho}\casaverde\node_modules\dotenv\lib'
ERROR in ./node_modules/dotenv/lib/main.js 1:11-24
Module not found: Error: Can't resolve 'fs' in 'C:\{caminho}\casaverde\node_modules\dotenv\lib'
ERROR in ./node_modules/dotenv/lib/main.js 2:13-28
Module not found: Error: Can't resolve 'path' in 'C:\{caminho}\casaverde\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 }
No console web o erro é:
Uncaught Error: Cannot find module 'fs'
at webpackMissingModule (main.js:1:1)
at ./node_modules/dotenv/lib/main.js (main.js:1:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/servidor/server.js (server.js:1:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/pages/Homepage.js (index.js:13:1)