#arminomari_error
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1222310782344106145
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Can you share more about where you're receiving this error?
well i downloaded the github, i followed the youtube tutorial, put in the env, and then theres two different folders, the server and the client, when i tried to npm run start the client it gave me that error in the terminal but the server worked
For the client, you'll need to use npm start . Do you receive the same error if you try this command instead?
yeah
Gotcha. Give me a few minutes
You'll need to install this package: https://www.npmjs.com/package/cross-env
The reason for this is that the client app is trying to set the port number in a way that is supported on Unix machines, and you're using Windows
Let me know if installing this package and starting the client server again gets you past this error
is it just to npm install --save-dev cross-env in the client?
Yep
it didnt work still got the same problem
Which version of Node.js are you using?
v.20.11.0
If you have it handy, could you share a screenshot of your terminal that shows the install of cross-env as well as your latest attempt to start the client?
Also, could you share what the client/react-cra/package.json file looks like locally?
Thanks! I see cross-env is included in devDependencies above so not sure why you're running into the same error
Give me a few more minutes
is it anything about this line that i could posible change? "scripts": {
"start": "PORT=4242 react-scripts start",
in my package.json?
oh, did you share package-lock.json with me instead of package.json?
oh maybe {
"name": "react-cra",
"version": "0.1.0",
"private": true,
"dependencies": {
"@stripe/react-stripe-js": "^1.10.0",
"@stripe/stripe-js": "^1.35.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "^3.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "PORT=4242 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write "**/*.{js,jsx}""
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5252",
"devDependencies": {
"cross-env": "^7.0.3",
"prettier": "^2.7.1"
}
}
here
mb
Did you change this file yourself after downloading from github? I'm not sure why there seems to be a mismatch here:
"start": "PORT=4242 react-scripts start",
"proxy": "http://localhost:5252/",
no i didnt
it came like that
but the host is right i belive
{
"name": "react-cra",
"version": "0.1.0",
"private": true,
"dependencies": {
"@stripe/react-stripe-js": "^1.10.0",
"@stripe/stripe-js": "^1.35.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "PORT=4242 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write "**/*.{js,jsx}""
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5252",
"devDependencies": {
"prettier": "^2.7.1"
}
} look this is direct from github
Can you link to the file on github?
Interesting, okay. We're looking at two different things
I recommend working with the code from stripe-samples
so i should restard with this one? https://github.com/stripe-samples/accept-a-payment/tree/main/payment-element
and try=
Yes, please restart with the code from stripe-samples. You'll likely need to run npm install --save-dev cross-env again
ait ait
ill get back to you
w8 just a question
how do i git clone this specific https://github.com/stripe-samples/accept-a-payment/tree/main/payment-element
it doesnt show me a show code
nvm
but this isnt the same used as in the tutorial bro
Basic functionality should be similar though
nah cant get it to work thx for the help though trynna use some other tutorial
Are you running into the same error or something else?
nah same error
and you ran npm install --save-dev cross-env again?
yeah
๐ roadrunner had to head out, but I'm around to answer questions if you need more help
bro everything is on linux i cant get it to work on windows
Which tutorial are you trying to get to work now? https://github.com/stripe-samples/accept-a-payment/tree/main/payment-element or https://github.com/matthewling-stripe/react-stripe-payment-element ?
Also, after install cross-env did you update the start command in your package.json to use it?
well w8 im finna start over again why not
i will try with this one https://github.com/matthewling-stripe/react-stripe-payment-element again
aight
same problme
and why does my .env look like that
Did you update the start command in your package.json
idk {
"name": "react-cra",
"version": "0.1.0",
"private": true,
"dependencies": {
"@stripe/react-stripe-js": "^1.10.0",
"@stripe/stripe-js": "^1.35.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "PORT=4242 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write "**/*.{js,jsx}""
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5252",
"devDependencies": {
"prettier": "^2.7.1"
}
}
this is how it looks
Yeah so you haven't actually used cross-env anywhere in there
i mean i could do it like this "start": "set PORT=4242 && react-scripts start" but then i get more problems
You need to do something like "start": "cross-env PORT=4242 react-scripts start",
What are you running npm run and not npm start?
sure - try it out and see what happens
Try this suggestion: https://stackoverflow.com/a/73807914/14107360
well i dont quiet understand how i should integrate that to my package.json
i got it
finaly
i got it
awesome ๐
thank you so much
hmm i am on the checkoout page and i just wanted to see if it would work so i copied your import { PaymentElement } from "@stripe/react-stripe-js";
import { useState } from "react";
import { useStripe, useElements } from "@stripe/react-stripe-js";
export default function CheckoutForm() {
const stripe = useStripe();
const elements = useElements();
const [message, setMessage] = useState(null);
const [isProcessing, setIsProcessing] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
if (!stripe || !elements) {
// Stripe.js has not yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
return;
}
setIsProcessing(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url: `${window.location.origin}/completion`,
},
});
if (error.type === "card_error" || error.type === "validation_error") {
setMessage(error.message);
} else {
setMessage("An unexpected error occured.");
}
setIsProcessing(false);
};
return (
<form id="payment-form" onSubmit={handleSubmit}>
<PaymentElement id="payment-element" />
<button disabled={isProcessing || !stripe || !elements} id="submit">
<span id="button-text">
{isProcessing ? "Processing ... " : "Pay now"}
</span>
</button>
{/* Show any error or success messages */}
{message && <div id="payment-message">{message}</div>}
</form>
);
} like that but mine looks like this
while your look like this
looks like your backend server returned a 404 response. so you need to fix that.
how do i fix it?
make sure your backend server is running, make sure you have a route called /create-payment-intent in your backend, make sure the code in that route is working properly, etc.
and i got it
does that mean you fixed the issue and its working?
if you get a 404 error, it either means:
- the server is not running, or running on a different port
- the route is not called
/create-payment-intent - or the URL you are using to call the backend is wrong
how do i know if the route is not called
what can i do to doubble check cause i just copy the github code
are you still getting a 404 error? then it means the route is not called.
are you sure your server is running, and it's on the correct port?
so it's on port 5252, but the error you shared you are using port 4242.
so it's expected to not work
in this screenshot you can see your frontend is trying to call your backend at the 4242 port, but it's on the 5252 port. so that can't work.
ah
well how do i fix that do i change it to the same port? that doesnt sound right haha
im trying but as you understand i am kinda new
can it do with the fact that i changed my package.json ? cause i added options but maybe i integrated it wrong or sum
cause mine and yours looks different now
not sure, having a look at https://github.com/matthewling-stripe/react-stripe-payment-element
I just downloaded the repo, then:
- renamed
.env.sampleinto.envand updated the values there - ran
npm insallandnpm initin the server/ folder - ran
npm insallandnpm initin the client/ folder - opened http://localhost:4242/ and it just works
and your using windows as well?
no, mac.
if you have trouble using the Payment Element, you might want to use Checkout Session or Payment Links, which are simpler to implement.
maybe try this? https://stackoverflow.com/questions/70374005/invalid-options-object-dev-server-has-been-initialized-using-an-options-object
I'm sorry I can't really help with this, since I'm not familiar with Windows and this question is unrelated to Stripe API.