ton-connect / sdk

SDK for TON Connect 2.0 — a comprehensive communication protocol between wallets and apps in TON ecosystem
Apache License 2.0
330 stars 98 forks source link

UI-REACT: Import Error with `@tonconnect/ui-react` in Next.js 14.0.2 #117

Closed num13ru closed 1 year ago

num13ru commented 1 year ago

Description

I'm experiencing an import error when using @tonconnect/ui-react in a Next.js 14.0.2 application. The specific error is related to TonConnectUIProvider not being exported as expected.

Error Message

   Attempted import error: 'TonConnectUIProvider' is not exported from '@tonconnect/ui-react' (imported as 'TonConnectUIProvider').

   Import trace for requested module:
   ./src/app/layout.tsx
   Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

   Check your code at layout.tsx:21.
    ⨯ Error: Unsupported Server Component type: undefined
       at stringify (<anonymous>)
    ⨯ Error: Unsupported Server Component type: undefined
       at stringify (<anonymous>)

Code Snippet

   import type { Metadata } from 'next';
   import { Inter } from 'next/font/google';
   import './globals.css';
   import { TonConnectUIProvider } from '@tonconnect/ui-react';

   const inter = Inter({ subsets: ['latin'] });

   const manifestUrl = 'https://my-next-app.vercel.app/tonconnect-manifest.json';

   export const metadata: Metadata = {
     title: 'Create Next App',
     description: 'Generated by create next app',
   };

   export default function RootLayout({
     children,
   }: {
     children: React.ReactNode;
   }) {
     return (
       <TonConnectUIProvider manifestUrl={manifestUrl}>
         <html lang="en">
           <body className={inter.className}>{children}</body>
         </html>
       </TonConnectUIProvider>
     );
   }

Additional Information

liketurbo commented 1 year ago

For next@13, it also yields an error, although a different one. It's worth noticing that i used "App Router (app directory)". Next@12 with the "Pages router" works fine, though.

hos commented 1 year ago

This error seems to be introduced in beta-5 beta-4 works with App Router

thekiba commented 1 year ago

It seems like the problem is related to a specific range of Next.js versions rather than an issue with TON Connect.

To resolve this, you have to update or rollback the NextJS version:

Please use one of these solutions.

antontuzov commented 6 months ago

Adding 'use client'; on top of the page fixed the error to me.

solbricklayer commented 6 months ago

fixed the error to me.

+1 on anton solution - fixed for me on next 14.2.3

ArchimedesCrypto commented 4 months ago

We should add the requirement of NextJs 14.0.4 to the readme. I spent hours trying to fix this until i found this