Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  100] [ 5]  / answers: 1 / hits: 87949  / 3 Years ago, fri, march 5, 2021, 12:00:00

I am going through Stripes integration steps and have come across an error for my code found in step 2.1 (https://stripe.com/docs/connect/collect-then-transfer-guide#create-an-account-link)


How do I fix this error?


Code:


const stripe = require('stripe')('someID');
const account = await stripe.accounts.create({
type: 'express',
});

Error:



Top-level 'await' expressions are only allowed when the 'module'
option is set to 'esnext' or 'system', and the 'target' option is set
to 'es2017' or higher.ts(1378)



More From » node.js

 Answers
46

You can wrap your code for const account inside an async function as your target option doesn't support top level await.


 const account = async () => {
await stripe.accounts.create({
type: "express",
});
};

It depends on your code whether you want to return something or you want to perform some other tasks after await.


Incase if you want to use top level await, More about using top level await is on https://stackoverflow.com/a/56590390/9423152


This it just a workaround of the problem not the exact solution as referred by other users.
Furthermore,
You can try changing the module option and target in tsconfig file if you are using Typescript on node.


[#50367] Tuesday, February 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quentinaveryb

Total Points: 102
Total Questions: 100
Total Answers: 93

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
quentinaveryb questions
Thu, Aug 6, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;