-
Notifications
You must be signed in to change notification settings - Fork 480
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
Uncaught RangeError: WebAssembly.Compile is disallowed on the main thread
when importing solc in Chrome
#456
Comments
Are you able to move this into a worker process? |
@chriseth when I use
it shows another error |
I am totally frustrated, please help me to require solc for my react web app to add solidity compiler in the web. |
It should be enough to use solc-js inside the worker.js - you should not run WebAssembly.compile yourself. |
@farooqahmad075 Try to use importScripts https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts inside worker to fetch solc binaries using url like https://solc-bin.ethereum.org/bin/soljson-v0.6.1+commit.e6f7d5a4.js |
Bump. This affects me too. Uncaught RangeError: WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.compile, or compile on a worker thread. I have code that uses cwrap, it used to work. Sadly no more. |
@Tectract are you sure that |
Hi, I'm closing this because, as pointed out here: #581 and by this comment: #456 (comment), it is currently required to use a web worker with solc-js in some browsers (chromium-based). You can see examples of how to accomplish it here: #456 (comment), and here: #627 (comment) @Tectract, here is an example of how you could use the cwrap if you need to use it directly (works on firefox). <script type="text/javascript" src="https://binaries.soliditylang.org/bin/soljson-v0.8.17+commit.8df45f5f.js"
integrity="sha256-YXgo5jvkhcfMLby91aIrWCtA+vqkEBatWVY3uDyQZWw=" crossorigin="anonymous">
</script>
<script type="text/javascript">
const soljson = window.Module;
let compile = null;
if ('_solidity_compile' in soljson) {
compile = soljson.cwrap('solidity_compile', 'string', ['string', 'number']);
}
const input = {
language: 'Solidity',
sources: {
'test.sol': {
content: 'contract C { function f() public { } }'
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
const output = JSON.parse(compile(JSON.stringify(input)))
// do something with the output
</script> |
thanks for the reference. I'll take a look at my code again. |
Uncaught RangeError: WebAssembly.Compile is disallowed on the main thread
when importing solc in Chrome
I'm receiving an error My worker.js: import solcjs from 'solc-js'
self.addEventListener('message', async e => {
const version = 'v0.8.23-stable-2023.11.07'
const compiler = await solcjs(version)
const sourceCode = `// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Example is ERC20 {
constructor() ERC20("Example", "EXM") {
_mint(address(this), 1_000 ** 18);
}
}`
const output = await compiler(sourceCode)
console.log(output)
self.postMessage({
success: true
})
}, false) |
When I try to include
var solc = require('solc');
in my react app I get an error in chrome console thatWhat is causing the issue? or how can I fix using WebAssembly?
The text was updated successfully, but these errors were encountered: