-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anchor provider depends on fs module #244
Comments
Agreed this is undesireable and should be fixed. |
@mschneider it appears the line where
Can you confirm how you are creating the
|
I’m using the sol wallet adapter and pass it in. I think the issue is that
the built module does reference it not that a line of code is actually
trying to execute it.
I simply configured bundler to ignore those missing references
…On Sat 8. May 2021 at 21:15, Armani Ferrante ***@***.***> wrote:
@mschneider <https://github.com/mschneider> it appears the line where fs
is used is using the NodeWallet.local api, i.e.
const payer = new Account(Buffer.from(JSON.parse(require("fs").readFileSync(require("os").homedir() + "/.config/solana/id.json", {
encoding: "utf-8",
}))));
Can you confirm how you are creating the wallet being used above? The
NodeWallet should not be used in a browser environment. One should use
sol-wallet-adapter or any javascript implementing the Wallet interface,
i.e.,
export interface Wallet {
signTransaction(tx: Transaction): Promise<Transaction>;
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
publicKey: PublicKey;
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#244 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABDF7DBNUFGWTAZRA65HQTTMV5SFANCNFSM44EQWWMA>
.
|
Sounds like the solution here is to either move the node wallet out of the main |
Does #436 close this @armaniferrante? |
I suspect it does but I haven't reproduced this issue to confirm. |
I think it should fix the Very basic demo of anchor being loaded in React without errors here - https://codesandbox.io/s/floral-star-3sk2w?file=/src/App.tsx |
Looks resolved to me based on this code sandbox. Please re-open if it's still an issue. |
I can't repro it on sandbox for some reason but this is still causing an exception for me. Does this line have to be gated behind |
Hmmm, I'm hitting this problem as well @woniesong92. 🤔 |
Wondering what you did to work around it @woniesong92? That's the line that has issues for me too. |
Because I'm using next.js which uses webpack, I simply added this in my
It'll work around it. 😃 Hopefully this helps someone! |
I am still seeing issues around the fs module in nextjs even with the above webpack config change. However the error is now pointing to
pointing to this line: https://github.com/project-serum/anchor/blob/cfba251fc4cb366adcd4ad48eefee2201d7448c5/ts/src/provider.ts#L236 |
I created a minimal repro repo for Next.js here: https://github.com/vpontis/anchor-next-fs-issue/tree/176a7f4a6f8f970097aec1ce3f8868cdde1bda3d Next.js is a pretty popular React framework and I think Anchor would benefit from working well with Next.js since it would make Solana beginner-friendly. Also, the webpack work around mentioned above is not ideal since that means Anchor and Next.js can't work with each other out of the box. @armaniferrante, any chance we can re-open this issue? I can look into how we can remove the |
@vpontis would be awesome if you took a look at this. |
the workaround from above works for the dev run, but fails for the prod build. Do you guys have suggestions on how to fix that? |
Bundling the anchor package for usage inside a browser-based react app is currently causing build failures. These can be circumvented by configuring webpack, but I think this kind of solutions is far from ideal, as it increases the friction for a first time anchor user. What would we need to change, to prevent the following issue?
I am using roughly the following code to create a new Program inside a react app
This will result in the following error:
I found a common workaround for this issue in this stack overflow post: https://stackoverflow.com/questions/57161839/module-not-found-error-cant-resolve-fs-in
The text was updated successfully, but these errors were encountered: