Troubleshooting

Pure ESM compile (Commonjs not supported)

We have adopted ESM syntax for the Tonomy codebase because of dependencies that we use that have taken a "pure ESM" stance.

You cannot consume the Tonomy SDK in a Commonjs project such as a default Node.js or Jest compiler.

Please change your compiler to target ESM.

  • Ensure "type": "module" in package.json

  • Use Nodejs ≥ 20.00

You may also need to set the environment variable NODE_OPTIONS="--experimental-vm-modules"

What is causing this?

We use the veramo.io libraries, which use pure ESM components. See here for more details. Check out our PRs to convert our codebases to pure-ESM.

The jsonld ecosystem

The Tonomy library use the Verifiable Credentials libraries (like @veramo/credential-ld) which depend on a set of libraries from the jsonld ecosystem which weren't designed with the same multi-platform targets in mind. Forks of these dependencies exist, that work in all environments where Veramo should work, but you have to aid your package manager in finding them.

The solution is to add a resolutions (or overrides) block to your package.json file and replacing the problematic dependencies:

package.json
"resolutions": {
    "jsonld": "link:./node_modules/@digitalcredentials/jsonld"
  },

Different package managers use different configurations for such overrides:

See the veramo troubleshooting issue for more details.

React Native / Expo apps​

If your project is a react-native app, then you will also benefit from replacing isomorphic-webcrypto with the fork maintained by Sphereon

package.json
"resolutions": {
  "isomorphic-webcrypto": "npm:@sphereon/isomorphic-webcrypto@^2.4.0"
}

See the veramo troubleshooting issue for more details.

yarn package management linking issues

Try use yarn with node-modules:

.yarnrc.yml
nodeLinker: node-modules

Error: Cannot read 'getResolver' of undefined

This has been observed in vite/quasar apps in development mode. To resolve see here: https://github.com/decentralized-identity/ethr-did-resolver/issues/186#issuecomment-1870230086

TypeError: Failed to execute 'fetch' on 'Window'

You need to override the fetch object used by the SDK when your app loads. Do this at the same time as you call setSettings()

import { setFetch } from '@tonomy/tonomy-id-sdk';

setFetch(window.fetch.bind(window));

Further support

Send us a message in the Tonomy Discord:

Last updated