Open ivanproskuryakov opened 1 month ago
@ivanproskuryakov I am experiencing the same, let me know if you find a good fix.
I am able to use Next's Script tag to load the TWA script and then do the JS there, but I would like to use this SDK.
@kevcube Sure, I'll open a PR with a patch. Meanwhile, can you post your workaround for this error, please?
@ivanproskuryakov
"use client";
import Script from "next/script";
import { Telegram } from "@twa-dev/types";
declare global {
interface Window {
Telegram: Telegram;
}
}
export default function Page() {
return (
<Script
id="TelegramWebApp"
src="https://telegram.org/js/telegram-web-app.js"
onReady={() => {
window.Telegram.WebApp.MainButton.setParams({
text: `Hello`,
is_visible: true,
});
}}
/>
);
}
I'm using Next 14, this can go in layout
or other imported files to auto load on all pages of your app.
The library fails to work with the Next.js framework ("next": "^12.1.6") while SSR.
The issue is caused by the missing window object within the file node_modules/@twa-dev/sdk/dist/sdk.js, and it occurs at the time of import. Ref: https://github.com/twa-dev/SDK/blob/master/src/sdk.ts
Transpiled file
Demo app:
Console output