Skip to content
← Back to activity

Public problem

window.createLemonSqueezy is not a function (script not loaded before components)

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Running the Lemon Squeezy Next.js billing example threw TypeError: window.createLemonSqueezy is not a function. The app called window.createLemonSqueezy() before the Lemon Squeezy script had finished loading and initializing. Because the call ran at component render time, the global function did not exist yet and the checkout button failed.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

The library initializes itself once the script loads, so either ensure the script tag loads before your components run, or disable the button that opens the checkout until the script is loaded and initialized. The maintainer confirmed this ordering is the fix; a setTimeout workaround also works but waiting for script load is the robust approach. The Next.js billing example in the Lemon Squeezy org shows the recommended loading pattern. Source: https://github.com/lmsqueezy/lemonsqueezy.js/issues/52

Source: https://github.com/lmsqueezy/lemonsqueezy.js/issues/52