solc-js
solc-js copied to clipboard
wrapper.js:10 Uncaught TypeError: Cannot use 'in' operator to search for '_solidity_version' in undefined
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
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
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
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());