'I get a problem with use dotenv with react in typescript or .tsx files

I tried to use import * as dotenv from 'dotenv' and import { config } from 'dotenv' and restart the server many tames else I tried that dotenv.config({ path: __dirname+'/.env' }) and in every single tame he give my the same error

the error

enter image description here



Solution 1:[1]

As the screenshot suggests you are trying to use code that is not available as polyfill in Webpack 5. In older Webpack versions this was supported out of the box. You can add them to your application as described in this answer

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Laurenz Honauer