Skip to content
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.BN is not a constructor #3473

Open
cxp-13 opened this issue Jan 9, 2025 · 2 comments
Open

anchor.BN is not a constructor #3473

cxp-13 opened this issue Jan 9, 2025 · 2 comments

Comments

@cxp-13
Copy link

cxp-13 commented Jan 9, 2025

BN is not a constructor

how to solve the BN problems when using anchor on eliza framework?

import * as anchor from "@coral-xyz/anchor";
const {BN} = anchor;

it's work on test

@cxp-13
Copy link
Author

cxp-13 commented Jan 9, 2025

if I change to use bn.js
also get another error

✘ [ERROR] Could not resolve "bn.js"

    src/actions/borrow.ts:55:19:
      55 │ import { BN } from "bn.js";
         ╵                    ~~~~~~~

@cxp-13
Copy link
Author

cxp-13 commented Jan 9, 2025

Solved: modify tsup.config.ts file, add library name that have resolved problem

import { defineConfig } from "tsup";

export default defineConfig({
    entry: ["src/index.ts"],
    outDir: "dist",
    sourcemap: true,
    clean: true,
    format: ["esm"], // Ensure you're targeting CommonJS
    external: [
        "dotenv", // Externalize dotenv to prevent bundling
        "fs", // Externalize fs to use Node.js built-in module
        "path", // Externalize other built-ins if necessary
        "@reflink/reflink",
        "@node-llama-cpp",
        "https",
        "http",
        "agentkeepalive",
        "safe-buffer",
        "base-x",
        "bs58",
        "borsh",
        "@solana/buffer-layout",
        "stream",
        "buffer",
        "querystring",
        "amqplib",
        "bn.js"   // <============== add here
        // Add other modules you want to externalize
    ],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant