Benco
Benco

Reputation: 130

Stripe.js was not loaded correctly

I'm loading stripe into my payment page like so:

<script src="https://js.stripe.com/v3/"></script>

This works perfectly in my local test environment but in production, the following console error appears:

Uncaught Error: It looks like Stripe.js was not loaded correctly
    at new e (controller-84824401a25a5595fc578f767b4d5c27.js:1)
    at controller-84824401a25a5595fc578f767b4d5c27.js:1
    at Object.bnjt (controller-84824401a25a5595fc578f767b4d5c27.js:1)
    at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
    at Object.3 (controller-84824401a25a5595fc578f767b4d5c27.js:1)
    at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
    at window.webpackJsonp (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
    at controller-84824401a25a5595fc578f767b4d5c27.js:1

I can't work out what might be causing the error. I'm using HTTPS in production and can see the JS file source downloading successfully. Any tips?

Upvotes: 4

Views: 2817

Answers (1)

Benco
Benco

Reputation: 130

Solved following advice from @NathanCasebolt. SO mods deleted his original answer:

“For me, the resolution to this error was as simple as spell-checking my variables. In my backend server code, one of my variables was wrongly capitalized. Since the misspelled variable was part of the function that retrieves my publishable key, the key returned from the server as null. This, in turn, disrupted creation of the Stripe object and threw this error. If I were you, I'd check to make sure (1) that the publishable key on your frontend matches the publishable key in your dashboard, and (2) that you're not doing anything that might disrupt serving this key to Stripe.”

The StackOverflow mods felt this didn’t answer the question and required too much clarification. So, to clarify, the problem for me was this line:

var stripe = Stripe(‘{PUBLISHABLE_KEY}’);

I set things up to retrieve my publishable keys from my server, to give me more flexibility in switching between test keys and live keys. Since my one of my server variables was wrong, I was providing Stripe with a bad key (no key, really), and that’s what threw the error. This is why I suggest you check the publishable key you’re using to create the Stripe object, to make sure that the one you’re using to create the object is there, and that it matches the publishable key you have on your Stripe dashboard."

In my case, this is exactly what I'd done wrong: provided an empty publishable key when initialising Stripe. Ultimately a very simple mistake compounded Stripe's obtuse error message.

Upvotes: 3

Related Questions