coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

Can't import Anchor into React project #3014

Closed mvrahas closed 2 weeks ago

mvrahas commented 3 weeks ago

I can't import Anchor into my freshly created React web app project. I get an error. Why is this happening? These are my steps to replicate below.

1) Create a new project npx create-react-app test

2) Enter project directory and install Anchor npm install @coral-xyz/anchor (^0.30.0)

3) Add a line to App.js to import Anchor import * as anchor from "@coral-xyz/anchor"

4) Run the project npm run start

5) Open http://localhost:3000 in Safari browser

6) Observe error in the browser

image

acheroncrypto commented 3 weeks ago

The first error line shows the error is coming from @solana/web3.js. You may need polyfills to fix the issue, see https://github.com/oven-sh/bun/issues/1749#issuecomment-1374974179.

acheroncrypto commented 2 weeks ago

You can also use create-solana-dapp which should work out of the box.