Error with top-level-await when integrating Firebase with Stripe Checkout session

I have been working on setting up a checkout session using the stripe firebase extension, but I encountered an error:

./pages/viewer.js Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enable it) File was processed with these loaders:

  • ./node_modules/next/dist/build/babel/loader/index.js You may need an additional loader to handle the result of these loaders. Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enable it)

I am unsure about what this error means, as it's a new concept for me.

I'm currently working with the next.js framework.

Here is a snippet of my code:

firebase.js file:

// Import the necessary functions from the SDKs
import { initializeApp } from "firebase/app";
// TODO: Add Firebase SDKs you require
// https://firebase.google.com/docs/web/setup#available-libraries

// Your Firebase configuration
const firebaseConfig = {
  apiKey: "AIzaSyAIbAZGEmnB5EMpj7TTR0v0yjK2c1EYJzo",
  authDomain: "comics-app-a4675.firebaseapp.com",
  projectId: "comics-app-a4675",
  storageBucket: "comics-app-a4675.appspot.com",
  messagingSenderId: "963431498351",
  appId: "1:963431498351:web:e1b078045362f3c168039a"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

Viewer.js file (Page used as success url):

import Head from 'next/head'
import Reader from '../components/Reader';
import Header from "../components/Header";
import Feed from "../components/Feed";
import Titles from "../components/Titles"
import React, { useState, useEffect } from 'react';

import { getApp } from "@firebase/app";
import { getStripePayments } from "@stripe/firestore-stripe-payments";
import { getProducts } from "@stripe/firestore-stripe-payments";
import { createCheckoutSession } from "@stripe/firestore-stripe-payments";
import { onCurrentUserSubscriptionUpdate } from "@stripe/firestore-stripe-payments";

const app = getApp();
const payments = getStripePayments(app, {
  productsCollection: "products",
  customersCollection: "customers",
});

const products = await getProducts(payments, {
  includePrices: true,
  activeOnly: true,
});
for (const product of products) {
  // ...
}

const session = await createCheckoutSession(payments, {
  price: myPriceId,
});
window.location.assign(session.url);

onCurrentUserSubscriptionUpdate(
  payments,
  (snapshot) => {
    for (const change in snapshot.changes) {
      if (change.type === "added") {
        console.log(`New subscription added with ID: ${change.subscription.id}`);
      }
    }
  }
);
function viewer() {
 
 


return (
        <div>
         <Head>
        <title>Minerva</title>
        <link rel="icon" href="/favicon.ico" />
      </Head>
     
        <Header />
          <Reader />  
          
          <div className="pl-28 m-8 text-white">
       <h1 className="text-2xl font-extrabold">Metroid, Chapter 2</h1>
        <p className="font-bold border-b">September 21st, 2021</p>
      </div> 
        
        <Feed />
       
        </div>
    )
}

export default viewer

Answer №1

Could it be that topLevelAwait is not enabled in your next.config.js file?

const settings = {
  webpack: (config) => {
    config.experiments = config.experiments || {}
    config.experiments.topLevelAwait = true
    return config
  },
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Endless re-renders induced by React-Table

While experimenting with a component that includes a table, I decided to give the react-table package a shot. The large component below is triggering endless calls to getRowModel. Additionally, there is a useEffect present to track re-renders unrelated to ...

Modify class upon click event

I've been trying to solve this question with a few answers I found, but none of them seem to work with my script. My goal is to change the class of the .icon-menu element when it's clicked. What would be the best approach to achieve this? $(&ap ...

Creating interactive dropdown menus with PHP and Catalyst using Jquery

Currently, I am working on incorporating cascading dropdown menus into a catalyst web app. The main goal is to allow users to select a database table from the first dropdown menu and have the columns of that table populate the second dropdown menu. To achi ...

Shade the entire td column in different colors depending on the characteristics of th

I am working with a table and here is the code for it: <table> <thead> <tr> <th style="width: 40%; text-align: center; vertical-align: center;">Nr.<br> crt.</th> <th style="font-weight: bold; wi ...

IntelliSense feature of Tailwinds not functioning properly in Next.js & vscode

For Github Issues, please click here. Remember that you can find the reproduction link at this page. Highlighted Information: Current Tailwindcss-intellisense version: 0.7.6; Current Tailwindcss version: 3.0.16 Package manager in use: NPM; Operating S ...

Developing a specialized collection of React components for efficient web development

I am currently in the process of developing my own library package for the first time. However, I have encountered a particular issue where despite successful compilation, the page fails to locate the module associated with my component within the library. ...

Encountering a parse error while trying to import an image in Next.js

I'm encountering an issue while trying to import an image in Next.js. Despite the image being located in the public folder, I am receiving an error when running the server. Can anyone provide assistance with this problem? Error: Failed to parse src ...

Tips on separating a function into two separate files in Node.js

Hey there! I am just starting to explore Node.js so bear with me if I make any mistakes. So, I have this file: exports.Client = function() { this.example = function(name, callback) { console.log(name); }; ...

Tips for changing an input value when clicked using JQuery

Struggling to create an interactive mind mapping tool using JQuery? One challenge I'm facing is editing the content of a div once it's been set. I've implemented a function that successfully adds text to a div within the (mind-container). H ...

Execute a JavaScript function prior to initiating an AJAX request

To streamline the process of making AJAX calls in my .NET project, I have developed a function called checkConnection that checks for internet connectivity before each call. However, currently, I am manually calling this function on every button click that ...

Is it possible for the NextJS Client component to only receive props after rendering props.children?

Encountering a puzzling issue that has me stumped... In my setup, I have a server side component that fetches data and then sends it over to the client component, which is all pretty standard. Here's where things get weird... When I log the data on ...

Sending MVC3 model information as JSON to a JavaScript block

My challenge is to correctly pass my MVC3 model into a script block on the client side. This is the approach I'm taking in my Razor view: <script type="text/javascript"> var items = @( Json.Encode(Model) ); </script> The "Model" in t ...

What causes variations in running identical code between the Node environment and the Chrome console?

let myName = "World"; function functionA() { let myName = "FunctionA"; return function() { console.log(this.myName); } } functionA()(); Executing the code above in my terminal with node results in undefined, while running it in Chrom ...

Configuring Laravel to operate on a specific port number?

Currently, I am utilizing nodejs, expressjs, and socket.io to trigger events on my web app via a mobile phone connected to the nodejs server. Although the app is primarily built in JavaScript, I have opted to use laravel for data storage within a database ...

Show the image on top of the div block as the AJAX content loads

Implementing this task may seem easy and common, but I am struggling to figure it out! What should take five minutes has turned into an hour of frustration. Please lend me your expertise in getting this done. I have a div container block: <div cla ...

Is there a way to create a diagonal movement for an image by clicking on another HTML element?

<!DOCTYPE html> <html> <head> <meta charset="UTF-9"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(function() { $(document).re ...

Accessing a child field from Firebase in a React Native application

My firebase data is structured like this: "Locations" : { "location01" : { "image" : "https://www.senecacollege.ca/content/dam/projects/seneca/homepage-assets/homepage_intl.jpg", "instructorNa ...

The font size appears significantly smaller than expected when using wkhtmltoimage to render

I am trying to convert text into an image, with a static layout and size while adjusting the font size based on the amount of text. I prefer using wkhtmltoimage 0.12.5 as it offers various CSS styling options. Currently, I am working on a Mac. Below is a ...

Ways to combine extensive value within an array containing various objects

I am working with an array of objects and I need to merge all the values of params within each object into a single object. Array [ Object { "key": "This week", "params": Object { "thisWeekfilterDistance": [Function anonymous], "this ...

Having trouble accessing the URL route by typing it in directly within react-router?

Having some trouble getting dynamic routes to work with react router. Whenever I enter a URL like localhost:3000/5, I receive the error message "cannot GET /5". Here is how my router is configured: class App extends Component { render() { retu ...