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 #2056

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

anchor.BN is not a constructor #2056

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

Comments

@cxp-13
Copy link

cxp-13 commented Jan 9, 2025

Describe the bug

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

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";
         ╵                    ~~~~~~~

To Reproduce

Expected behavior

Screenshots

Additional context

@cxp-13 cxp-13 added the bug Something isn't working label Jan 9, 2025
@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
    ],
});

@AIFlowML
Copy link
Collaborator

AIFlowML commented Jan 9, 2025

Solved by modify tsup.config.ts
@cxp-13 If i something that need to be noted send a PR please.

@AIFlowML AIFlowML closed this as completed Jan 9, 2025
@AIFlowML AIFlowML added Need Feedback and removed bug Something isn't working labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants