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

Static import of my env vars and config breaks the usage of the lib #544

Open
3 tasks done
gvko opened this issue Oct 9, 2023 · 0 comments
Open
3 tasks done

Static import of my env vars and config breaks the usage of the lib #544

gvko opened this issue Oct 9, 2023 · 0 comments
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@gvko
Copy link

gvko commented Oct 9, 2023

  • I'm submitting a ...

    • Support request
  • What is the current behavior and expected behavior?

I have an index.ts file and a local.ts config file, which has some env vars. The config file looks like this:

export default {
  // different object props and their values
}

If I want to load the config at the start of my application, which runs the program, I can do it in two ways.

First one:

import * as dotenv from 'dotenv'
dotenv.config()
import localConfig from './local'

async function main() {
  let config: any = localConfig
  // start my app
}
main()

Second one:

import * as dotenv from 'dotenv'
dotenv.config()

async function main() {
  let config: any = (await import(`./local`)).default
  // start my app
}
main()

You can see that in the first way I use a static import and in the second, a dynamic import.
When I use a dynamic import, everything works, but when I use static import, I get the following error:

node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@polkadot/wasm-crypto/cjs/bundle.js:46
      throw new Error('The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');

At the start of my app I call

await cryptoWaitReady()

And later on

    const keyring = new Keyring({ type: 'sr25519' })
    this.signer = keyring.addFromMnemonic(signer)

At .addFromMnemonic() is where the error is triggered.

I don't rly understand why this happens, because in both cases config is loaded correctly (with the signer that is used in the keyring), and await cryptoWaitReady() returns true, before I call the keyring initialization.

  • Please tell us about your environment:

    • Version: 6.4.1

    • Environment:

      • Node.js
    • Language:

      • TypeScript (tsc --version: 5.2.2)
@TarikGul TarikGul added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
Development

No branches or pull requests

2 participants