iotaledger / iota-sdk

The IOTA SDK provides developers with a seamless experience to develop on IOTA by providing account abstractions and clients to interact with node APIs.
Apache License 2.0
57 stars 41 forks source link

[Bug]: Error while importing the web version in webpack #2255

Open Druelik opened 4 months ago

Druelik commented 4 months ago

Issue description

After updating to the latest version 1.1.3 and following the examples. Webpack reports error while importing the wasm library.

OutputDiscriminator seems to be undefined. At least it is that, what webpack reports back as error.

Returning to version 1.1.2 fixes the Problem.

Version

@iota/sdk-wasm : 1.1.3

Expected behaviour

Import should work without errors

Actual behaviour

Webpack errors on the import.

Can the issue reliably be reproduced?

Yes

Steps to reproduce the issue

  1. Follow the example, with webpack
  2. Import the lib
  3. See the crash in the browser.

Errors

Log:

Uncaught TypeError: _output__WEBPACK_IMPORTED_MODULE_2__ is undefined
    OutputDiscriminator index.js:21
    OutputResponse output-response.ts:20
    <anonymous> output-response.ts:23
    node_modules chunk-vendors.js:867

Screenshot: image

Duplicate declaration

sdellava commented 3 months ago

I've a very similar issue.

This is the simple code I've added in a EXPO project:

import { IotaIdentityClient, Resolver } from '@iota/identity-wasm/web';
import { Client } from '@iota/sdk-wasm/web';

export async function resolveDID(did: string): Promise<string> {

  const nodeUrl = 'https://api.testnet.shimmer.network/';
  const client = new Client({
    primaryNode: nodeUrl,
    localPow: true,
  });

  const didClient = new IotaIdentityClient(client);

  const resolver = new Resolver({  client: didClient  });
  try {
    const resolvedDocument = await resolver.resolve(did);
    return JSON.stringify(resolvedDocument, null, 2);
  } catch (error) {
    throw new Error(Failed to resolve DID: ${error});
  }
}

And this is the result:

lib installation:

yarn add @iota/sdk-wasm yarn add v1.22.22 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning " > @rneui/base@4.0.0-rc.7" has unmet peer dependency "react-native-vector-icons@>7.0.0". warning "expo-splash-screen > @expo/prebuild-config@6.0.1" has unmet peer dependency "expo-modules-autolinking@>=0.8.1". warning "react-native > react-native-codegen > jscodeshift@0.14.0" has unmet peer dependency "@babel/preset-env@^7.1.6". warning "jest-expo > jest-watch-typeahead@2.2.1" has unmet peer dependency "jest@^27.0.0 ^28.0.0 ^29.0.0". warning Workspaces can only be enabled in private projects. [4/4] Building fresh packages... warning Workspaces can only be enabled in private projects. success Saved 1 new dependency. info Direct dependencies └─ @iota/sdk-wasm@1.1.3 info All dependencies └─ @iota/sdk-wasm@1.1.3 Done in 11.04s.

test: PS C:.....> npx expo start Starting project at C:..... Some dependencies are incompatible with the installed expo version: @expo/config@8.1.1 - expected version: ~8.0.0 Your project may not work correctly until you install the correct versions of the packages. Install individual packages by running npx expo install @expo/config@~8.0.0 Error: Cannot find module '@iota/sdk-wasm/web'