[React Native] import.meta is only valid inside modules error when importing initOnlyAsm
See original GitHub issueAfter updating to the latest dependencies:
"@polkadot/api": "^8.6.1",
"@polkadot/keyring": "^9.3.1",
"@polkadot/util": "^9.3.1",
"@polkadot/util-crypto": "^9.3.1",
"@polkadot/wasm-crypto": "^6.1.1",
and adding import '@polkadot/wasm-crypto/initOnlyAsm'; at the top of index.js file, I’m getting import.meta is only valid inside modules error for both iOS and Android.

Issue Analytics
- State:
- Created a year ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
TS1343: The 'import.meta' meta-property is only allowed when ...
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports.
Read more >How should we handle import.meta #6719 - GitHub
In webpack's use case, it'd be useful to put import.meta.hot in it. ... imports in webpack, but as only importing JS is the...
Read more >import-meta-resolve - npm
Start using import-meta-resolve in your project by running `npm i import-meta-resolve`. There are 87 other projects in the npm registry ...
Read more >Cannot Create Polkadot Keyring with React Native - ADocLib
[React Native] import.meta is only valid inside modules error when importing initOnlyAsm.Original URL.After updating to the latest dependencies: @polkadot/.
Read more >Issue #417 (import.meta, Testing, React, Git/CLI)
The import.meta object currently exposes a single property: import.meta.url. This is the URL from which the module was loaded (in Node this is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey all, I have discovered a workaround to get it working on Android. Basically, from my findings it seems that the WASM errors get thrown even if you insert Platform checking logic to prevent code execution i.e. doing
if (Platform.OS === 'android') return;will still cause the WASM errors to get thrown, so I suspect it might have something to do with the bundling stages but I’m not entirely sure…Today I discovered the workaround by chance, I remembered reading somewhere there was a way to do lazy imports so I did a quick research, tested and landed on this solution that worked for me.
At the top of the file you can have something like this:
Then in the code below:
Then you can now use
Keyringfunctions.This solution might not work properly if you need to use PolkadotJS library within a constructor of a class. For use within a constructor, something like this should work:
If your IDE complains that the lazy imports above are not supported, you just need to add something like
"module": "esnext"under"compilerOptions"insidetsconfig.jsonfile (this is if you’re using TypeScript).Also note I did not need to do
initOnlyAsmas I initially did.There are probably more elegant solutions but this seems suffice to get PolkadotJS working on Android for now. Please feel free to share if you find a more elegant way for this workaround. Would love to know. Thanks!
After install
wasm-crypto6.1.5 and clear react-native cache withreact-native start --reset-cache.Everything seem be ok like initOnlyAsm with some basic function like
blake2AsHexand element likeIdenticon.