magiclabs / magic-js

Magic browser/React Native JavaScript SDK is your entry-point to integrating passwordless authentication inside your application.
https://magic.link/docs/api-reference/client-side-sdks/web
Apache License 2.0
462 stars 86 forks source link

SolanaExtension is not a constructor when using @magic-ext/solana in react-native #265

Closed bmeeder22 closed 2 years ago

bmeeder22 commented 2 years ago

✅ Prerequisites

🐛 Description

When attempting to use @magic-ext/solana in a build of React Native the build will error out with the following error:

SolanaExtension is not a constructor

🤔 Expected behavior

When using this exact same import scheme in regular web the Magic object is able to be initialized with no errors.

😮 Actual behavior

We see the following warning:

Screen Shot 2022-01-18 at 5 03 04 PM

Screenshot of the error:

Screen Shot 2022-01-18 at 5 05 32 PM

This is most likely due to some issue with the fact that index.native.js is referencing itself and is not importing correctly. We can see this issue happening in this stack overflow issue

💻 Code Sample

import {Magic} from '@magic-sdk/react-native';
import {SolanaExtension} from '@magic-ext/solana';

  const magic = new Magic('pk_live_xxxxx', {
    extensions: [
      new SolanaExtension({
        rpcUrl: 'https://api.devnet.solana.com',
      }),
    ],
  });

🌎 Environment

Software Version(s)
@magic-sdk/react-native 7.0.0
@magic-ext/solana 3.1.0
Browser react native
yarn 1.22.17
Operating System ios
bmeeder22 commented 2 years ago

Note: Manually changing export * from './index' => export { SolanaExtension } from './index.js'; fixes the issue.

However this will require a code change in index.native.ts

index ea465c2..d7e865e 100644 --- a/packages/@magic-ext/solana/src/index.native.ts +++ b/packages/@magic-ext/solana/src/index.native.ts @@ -1 +1 @@ -export * from './index'; +export {SolanaExtension} from './index.js';

smithki commented 2 years ago

:rocket: Issue was released in @magic-ext/conflux@0.1.1, @magic-ext/solana@3.0.1 :rocket: