Ecpair – Earlybirds Invest https://earlybirdsinvest.com Latest Crypto News Mon, 07 Jul 2025 13:16:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.8 https://i0.wp.com/earlybirdsinvest.com/wp-content/uploads/2024/12/cropped-New-Project-2024-12-17T235703.455.png?fit=32%2C32&ssl=1 Ecpair – Earlybirds Invest https://earlybirdsinvest.com 32 32 240146708 Tiny-Secp256k1 and Ecpair Webpack Issues https://earlybirdsinvest.com/tiny-secp256k1-and-ecpair-webpack-issues/ https://earlybirdsinvest.com/tiny-secp256k1-and-ecpair-webpack-issues/#respond Mon, 07 Jul 2025 13:16:24 +0000 https://earlybirdsinvest.com/tiny-secp256k1-and-ecpair-webpack-issues/ I’ve developed a browser extension using Webpack V5 and created a Bitcoin wallet with the Bitcoinjs-Lib and Ecpair libraries. However, when I try to load the WebAssembly module, I am getting an error.

I would greatly appreciate any guidance or suggestions on how to successfully resolve this issue and instantiate the WebAssembly module in a browser extension.

Error Message:

Enter the image description here

Here is an important detail of my setup.

  • I’m using Webpack V5 to bundle my applications.
  • I included the Bitcoinjs-Lib and the Ecpair library as dependencies for my project.
  • When I try to import Tiny-SECP256K1, I also get an error when passing that instance to ecpairfactory.

Enter the image description here

My webpack.config.js file:

const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { exec } = require("child_process");
const fs = require("fs");

function copyFolderSync(from, to) {
  fs.mkdirSync(to, { recursive: true });
  fs.readdirSync(from).forEach((element) => {
    if (element !== "manifest.json") {
      if (fs.lstatSync(path.join(from, element)).isFile()) {
        fs.copyFileSync(path.join(from, element), path.join(to, element));
      } else {
        copyFolderSync(path.join(from, element), path.join(to, element));
      }
    }
  });
}

module.exports = {
  module: {
    rules: (
      {
        test: /\.scss$/,
        use: ("style-loader", "css-loader", "sass-loader"),
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ("@babel/preset-env", "@babel/preset-react"),
          },
        },
      },
      {
        test: /\.wasm$/,
        type: "webassembly/async", // or "webassembly/sync"
      },
    ),
  },
  experiments: {
    asyncWebAssembly: true,
  },
  resolve: {
    extensions: (".js", ".jsx"),
    fallback: {
      buffer: require.resolve("buffer"),
      stream: require.resolve("stream-browserify"),
    },
  },
  entry: {
    background: "./app/background.js",
    popup: "./app/popup.js",
  },
  output: {
    path: path.resolve(__dirname, "dist/chrome"),
    filename: "(name).js",
  },
  plugins: (
    new HtmlWebpackPlugin({
      template: "./app/popup.html",
      filename: "popup.html",
      chunks: ("popup"),
    }),
    new CopyPlugin({
      patterns: (
        {
          from: "app",
          to: "",
          globOptions: {
            ignore: (
              "**/background.js",
              "**/popup.js",
              "**/popup.html",
              "**/build-types",
              "**/manifest",
            ),
          },
        },
        {
          from: "ui",
          to: "ui",
        },
      ),
    }),
    {
      apply: (compiler) => {
        compiler.hooks.afterEmit.tap("AfterEmitPlugin", (compilation) => {
          // Run the JavaScript file after the compilation is done
          exec("node development/build/index.js", (error, stdout, stderr) => {
            if (error) {
              console.error(`exec error: ${error}`);
              return;
            }
            // Copy files from the temp folder to other folders
            fs.readdirSync(path.resolve(__dirname, "dist")).forEach((dest) => {
              copyFolderSync("dist/chrome", `dist/${dest}`);
            });
          });
        });
      },
    },
  ),
};
]]>
https://earlybirdsinvest.com/tiny-secp256k1-and-ecpair-webpack-issues/feed/ 0 46275