Can't resolve 'fs'
When I load dotenv without webpack, I have the following message : Module not found: Error: Can't resolve 'fs' in '[MYPATH]\node_modules\dotenv\lib' ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in '[MYPATH]\node_modules\dotenv\lib'
I don't use webpack and can't change webpack config
The fs module is core to Node.js which is the intended environment for dotenv. If you want to manage environment variables on the client, I would suggest using webpack's built-in replacement feature or just if/switch statements.
Just wanted to share another alternative as mentioned here: https://github.com/webpack-contrib/css-loader/issues/447#issuecomment-285598881
Add the following to your Webpack config:
node: {
fs: "empty"
}
This makes the job as well.
const webpackConfig = { target: 'node' };
module.exports = webpackConfig; // Export all custom Webpack configs.
As mentioned above, dotenv is really only intended for the server.
If you're trying to work w/ the client, and you're using webpack, you can leverage the dotenv-webpack module. I've found it works pretty well.
This makes the job as well.
const webpackConfig = { target: 'node' };
module.exports = webpackConfig; // Export all custom Webpack configs.
how can I fix that on client?

I found this solution in stack overflow and it works for me. So, you can give it a shot.
if you encounter this error with a create-react-app app, you need to go to the 'react-scripts' webpack config.
node_modules/react_scripts/config/webpack.config.js
under 'resolve':
resolve: { .... // add the fallback setting below fallback: { "fs": false, "os": false, "path": false }, .... } Share Improve th