import { useState } from "react"; import dotenv from "dotenv"; import styled from…
- User
import { useState } from "react"; import dotenv from "dotenv"; import styled from "styled-components"; import Navbar from "../components/Navbar"; import PromoInfo from "../components/PromoInfo"; import Footer from "../components/Footer"; import RemoveIcon from "@mui/icons-material/Remove"; import AddIcon from "@mui/icons-material/Add"; import { useAppSelector } from "../redux/store"; import StripeCheckout from "react-stripe-checkout"; import { Token } from "react-stripe-checkout"; dotenv.config(); const KEY = process.env.REACT_APP_STRIPE; type ButtonProps = { buttonType?: "filled"; }; type SummaryItemProps = { type?: string; }; const Container = styled.div
; const Wrapper = styled.div` padding: 20px; `; const Title = styled.h2` font-weight: 300; text-align: center; `; const Top = styled.div` display: flex; justify-content: space-between; align-items: center; padding: 20px; `; const TopButton = styled.button<ButtonProps>` padding: 10px; font-weight: 600; cursor: pointer; border: ${(props) => (props.buttonType === "filled" ? "none" : null)}; background-color: ${(props) => props.buttonType === "filled" ? "black" : "transparent"}; color: ${(props) => (props.buttonType === "filled" ? "white" : null)}; `; const TopTexts = styled.div; const TopText = styled.spantext-decoration: underline; cursor: pointer; margin: 0 10px;; const Bottom = styled.divdisplay: flex; justify-content: space-between;; const Information = styled.divflex: 3;; const Product = styled.divdisplay: flex; justify-content: space-between;; const ProductDetail = styled.divflex: 2; display: flex;; const Image = styled.imgwidth: 200px;; const Details = styled.divpadding: 20px; display: flex; flex-direction: column; justify-content: space-around;; const ProductName = styled.span; const ProductId = styled.span; const ProductColor = styled.divwidth: 20px; height: 20px; border-radius: 50%; background-color: ${(props) => props.color};; const PriceDetail = styled.divflex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;; const ProductAmountContainer = styled.divdisplay: flex; justify-content: center; align-items: center; margin-bottom: 20px;; const ProductAmount = styled.divfont-size: 24px; margin: 5px;; const ProductPrice = styled.divfont-size: 30px; font-weight: 200;; const Hr = styled.hrbackground-color: #5a5959; border: none; height: 1px;; const Summary = styled.divflex: 1; border: 0.5px solid black; border-radius: 10px; padding: 20px;; const SummaryTitle = styled.h2font-weight: 200;; const SummaryItem = styled.divmargin: 30px 0; display: flex; justify-content: space-between; font-weight: ${(props) => (props.type === "total" ? 500 : null)}; font-size: ${(props) => (props.type === "total" ? "24px" : null)};; const SummaryItemText = styled.span; const SummaryButton = styled.button; - Assistant
It's possible that the ".env" file is not located in the root directory of your project. According to the dotenv documentation, the ".env" file should be placed in the root directory of your project, and not in any subfolder.
It's also possible that the name of your ".env" file is different from what you have specified in your code. By default, dotenv looks for ".env" file, but if you have named your file differently you need to specify it explicitly.
Make sure that you have installed the dotenv package correctly and added it to your dependencies in the package.json file.
- User
Module not found: Error: Can't resolve 'path' in 'C:\Users\48537\Documents\projektyreact\project11shop-fullstack\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 }
- Assistant
This error occurs because the
import path from 'path'statement in thedotenvpackage is trying to import the 'path' module, which used to be included by webpack < 5 but is no longer included by default in webpack 5.To fix this error, you need to add a fallback for the 'path' module in the webpack configuration.
Add the following code in the
webpack.config.jsfile, inside theresolveobject:javascriptresolve: { fallback: { "path": require.resolve("path-browserify") } }Then, install the
path-browserifypackage by running the following command in your terminal:codenpm install path-browserify --save-devThis should resolve the 'path' module import issue in the
dotenvpackage. - User
I don't want brwosefily write corect component
- Assistant
If you don't want to include a polyfill for the 'path' module, you can use an alternative method to load your environment variables. Instead of using the
dotenvpackage to load the environment variables from a.envfile, you can use thewebpack.DefinePlugin()to define your environment variables at build time.Here's an example of how to use the
webpack.DefinePlugin()in your webpack configuration file:javascriptconst webpack = require('webpack'); const path = require('path'); module.exports = { // Other webpack configuration options... plugins: [ // Define environment variables new webpack.DefinePlugin({ 'process.env.STRIPE': JSON.stringify(process.env.STRIPE), // Add other environment variables here... }), ], }; - User
I don't seeany webapck file it react project
- Assistant
By default, Create React App (CRA) hides the webpack configuration from the user. If you need to customize the webpack configuration in a CRA project, you can either eject the project (permanently exposing the configuration files) or use a third-party library like
react-app-rewiredorcracoto customize the webpack configuration without ejecting.Here's an example of how to use
cracoto customize the webpack configuration:-
Install
craco:codenpm install @craco/craco --save-dev
-