solc-js icon indicating copy to clipboard operation
solc-js copied to clipboard

wrapper.js:10 Uncaught TypeError: Cannot use 'in' operator to search for '_solidity_version' in undefined

Open xx014939 opened this issue 2 years ago • 3 comments

Description

Hey guys, I have been trying to use solc in a React.js app for around a week now, and I can't get it to work!

I am importing solc using the following statements

import * as wrapper from 'solc/wrapper'; const solc = wrapper(window.Module);

However, upon compiling I get the following error in the browser

wrapper.js:10 Uncaught TypeError: Cannot use 'in' operator to search for '_solidity_version' in undefined

I've tried a number of ways around this, but none seem to work Has anyone else had a similar issue? Thanks

xx014939 avatar Sep 09 '22 20:09 xx014939

Hi @xx014939, can you provide more details of your setup? What version of solc-js are you using?

Probably related to https://github.com/ethereum/solc-js/issues/627

r0qs avatar Sep 12 '22 10:09 r0qs

Hi @xx014939, can you provide more details of your setup? What version of solc-js are you using?

Probably related to #627

Hey @r0qs

The package.json file of the node module contains the following properties

"name": "solc", "version": "0.8.16", "description": "Solidity compiler", "main": "index.js", "bin": { "solcjs": "solc.js" },

So I'm on version 0.8.16.

_solidity-version is only mentioned once in wrapper.js, on line 36 which reads as follows

let version; if ('_solidity_version' in soljson) { version = soljson.cwrap('solidity_version', 'string', []); } else { version = soljson.cwrap('version', 'string', []); }

Thanks

xx014939 avatar Sep 12 '22 16:09 xx014939

Hi @xx014939, in which browser are you testing? Chromium-based browsers seem to have a problem loading the wasm binary in the main thread. So you are currently required to use a web worker. You can see here: https://github.com/ethereum/solc-js/issues/627#issuecomment-1243501953 an example of how to do it.

However, if you are using firefox, this should work:

...
<script type="text/javascript" src="https://binaries.soliditylang.org/bin/soljson-v0.8.16+commit.07a7930e.js"></script>
<script type="text/javascript" src="<path_to_where_your_bundle_is>/bundle.js"></script>
...
import wrapper from 'solc/wrapper';
...
const solc = wrapper(window.Module);
console.log(solc.version());

r0qs avatar Sep 26 '22 14:09 r0qs