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

Can't import the browser build using a bundler #156

Open
ggcaponetto opened this issue Nov 23, 2021 · 1 comment
Open

Can't import the browser build using a bundler #156

ggcaponetto opened this issue Nov 23, 2021 · 1 comment

Comments

@ggcaponetto
Copy link

Version

3.6.0 - Browser

Expectation

I should be able to import the module with a bundler like webpack.

The online demo shows how to import the cardano-addresses module served from a webserver root.

Actual Behaviour

Unfortunately I am not able to reproduce the sample in this stackblitz example.

import React, { Component, useEffect, useState } from 'react';
import { render } from 'react-dom';
function App() {
  const [info, setInfo] = useState(null);
  const [cardanoAddresses, setCardanoAddresses] = useState(null);
  const addr =
    'addr1gqtnpvdhqrtpd4g424fcaq7k0ufuzyadt7djygf8qdyzevuph3wczvf2dwyx5u';
  useEffect(() => {
    import('cardano-addresses/dist/cardano-addresses.esm.js').then((mod) => {
      console.log('imported cardano-addresses module', mod);
      setCardanoAddresses(mod);
    });
  }, []);
  useEffect(() => {
    if (cardanoAddresses) {
      console.log('init', { addr, cardanoAddresses });
      cardanoAddresses
        .inspectAddress(addr)
        .then((info) => {
          console.log('address info is:', info);
          setInfo(info);
        })
        .catch((e) => {
          setInfo(e.message);
        });
    }
  }, [cardanoAddresses]);
  return (
    <div>
      <h4>cardano-address-react sample</h4>
      <p>{JSON.stringify(info)}</p>
    </div>
  );
}

render(<App />, document.getElementById('root'));

The import of cardano-addresses/dist/cardano-addresses.esm.js succeedes, but as soon as I call the cardanoAddresses.inspectAddress(addr) function, I get the error ./cardano-addresses-jsapi.cjs.js: ES module loading failed!.
Any advice would be really appeciated!

@leobel
Copy link

leobel commented Mar 1, 2022

Hi @ggcaponetto did you find a solution for this? I'm having the same issue using Angular.

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

2 participants