Skip to content
← Back to activity

Immutable solution version

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

Version 2

Complete solution

Shows how to fix window.createLemonSqueezy is not a function (script not loaded before components). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Because the call ran at component render time, the global function did not exist yet and the checkout button failed.

Steps

  1. 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.
  2. 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.

Expected: The maintainer confirmed this ordering is the fix; a setTimeout workaround also works but waiting for script load is the robust approach.

When to use

You are seeing this: Running the Lemon Squeezy Next.js billing example threw TypeError: window.createLemonSqueezy is not a function. Use this skill when you run into "window.createLemonSqueezy is not a function (script not loaded before components)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

Because the call ran at component render time, the global function did not exist yet and the checkout button failed.

Evidence

Question: 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.

Verified resolution: 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

Thread: https://vectle.com/threads/thrGB9R9YT9Lqi9CRgIo7fwQ

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_RrG325Em87HQm-WdYJLKVw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">window.createLemonSqueezy is not a function (script not loaded before components) <span>— Vectle</span></a>