Code Monkey home page Code Monkey logo

Comments (8)

birimbau avatar birimbau commented on June 12, 2024

Im using this in the browser in a simple Create React App application.

The versions I'm using:

"tiny-secp256k1": "^2.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^7.27.1",
"react-router-dom": "^6.2.1",
"react-scripts": "5.0.0",
webpack: 5.69.1
webpack-cli: 4.9.2
webpack-dev-server 4.7.4

Im also using Craco to overrride the default React CRA webpack configs whith the following configuration in craco.config.js:


module.exports = {
    webpack: {
        configure: {
            resolve: {
                fallback: {
                    process: require.resolve("process/browser"),
                    zlib: require.resolve("browserify-zlib"),
                    stream: require.resolve("stream-browserify"),
                    util: require.resolve("util"),
                    buffer: require.resolve("buffer"),
                    asset: require.resolve("assert")
                },
            },
            plugins: [
                new webpack.ProvidePlugin({
                    Buffer: ["buffer", "Buffer"],
                    process: "process/browser",
                }),
            ],
        },
    },
};

from tiny-secp256k1.

junderw avatar junderw commented on June 12, 2024

See this comment: bitcoinjs/bitcoinjs-lib#1777 (comment)

This is not an issue with bitcoinjs-lib or tiny-secp256k1.

This is an issue with your config or react / webpack itself. Since we have a working example using react and webpack, it's probably because you lack the asyncWebAssembly option in your webpack config.

from tiny-secp256k1.

Janaka-Steph avatar Janaka-Steph commented on June 12, 2024

I would say this is an issue with tiny-secp256k1 because the lib is using NodeJS modules so it cannot work out-of-the box in the browser. And now that Webpack 5 has decided to remove NodeJS polyfills it becomes a pain to install it.

from tiny-secp256k1.

junderw avatar junderw commented on June 12, 2024

Where does tiny-secp256k1 use NodeJS modules? (That isn't inside a file that is specified for NodeJS environment only in the package.json exports)

from tiny-secp256k1.

Janaka-Steph avatar Janaka-Steph commented on June 12, 2024

I didn't dig where modules are used but here https://github.com/bitcoinjs/tiny-secp256k1/blob/master/examples/react-app/webpack.config.js#L41-L44 if you have to polyfill it means that they are used.

from tiny-secp256k1.

junderw avatar junderw commented on June 12, 2024

https://github.com/bitcoinjs/tiny-secp256k1/blob/master/examples/react-app/index.js

The example app uses Buffer. This is not the library.

from tiny-secp256k1.

junderw avatar junderw commented on June 12, 2024

I have removed NodeJS dependencies in the example app to prove that the main library (which I have not touched) does not use NodeJS.

See #82

from tiny-secp256k1.

Janaka-Steph avatar Janaka-Steph commented on June 12, 2024

Ok so the error in the issue description Uncaught TypeError: Cannot read properties of undefined (reading 'buffer') is only due to lack of asyncWebAssembly property. I misinterpreted the error message. I still have to eject the webpack config in create-react-app to add that property but it's not an issue with the lib. Thank you for you quick reply.

from tiny-secp256k1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.