anza-xyz / wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.
https://anza-xyz.github.io/wallet-adapter/
Apache License 2.0
1.44k stars 906 forks source link

Webpack typeError, fails in NextJS 14 and 13 (react 18.2.0) #944

Closed PortsZ closed 2 months ago

PortsZ commented 2 months ago

Describe the bug While trying the example in "https://www.soldev.app/course/interact-with-wallets" , in a new NextJS 14 and 13 environement created with

npx create-next-app@latest

console gave this error:

[...]
 ⨯ ../node_modules/@solana/wallet-adapter-react/lib/esm/useConnection.js (2:47) @ eval
 ⨯ TypeError: (0 , react__WEBPACK_IMPORTED_MODULE_0__.createContext) is not a function
    at eval (webpack-internal:///(rsc)/../node_modules/@solana/wallet-adapter-react/lib/esm/useConnection.js:8:93)
    at (rsc)/../node_modules/@solana/wallet-adapter-react/lib/esm/useConnection.js
[...]

To Reproduce Steps to reproduce the behavior:

  1. In terminal type npx create-next-app@latest
  2. copy the code in the exemple: solana course
  3. Scroll down to @solana/wallet-adapter-react-ui, paste the code in /src/page.tsx and import missing useMemo from react
  4. run npm run dev

Expected behavior page to load

Screenshots image

Desktop (please complete the following information):

PortsZ commented 2 months ago

Got it working!! the 'use client'; directive should be written on the top of the file for the provider to work!

maybe should add error handling for this provider!