rexdavinci / browser-solidity-compiler

18 stars 7 forks source link

Uncaught ReferenceError: o is not defined #3

Closed ericleponner closed 1 year ago

ericleponner commented 1 year ago

I'm using browser-solidity-compiler from a VueJS application.

When I run on my local dev environment, everything works fine : solidityCompiler() loads and runs the compiler perfectly.

However when I deploy my VueJS app on an production host, solidityCompiler() throws the following error in navigator console:

Uncaught ReferenceError: o is not defined

Have you ever face this kind of issue ? Thanks for any help

ericleponner commented 1 year ago

After investigations, it looks like component is crashing on browser.solidity.worker.ts line 15.

I see that importScripts() is kind of stub : it seems to be ok with vuejs dev environment but not in production. Do I need to provide some code here ?

function browserSolidityCompiler() {
  const ctx: Worker = self as any;

  ctx.addEventListener('message', ({ data }) => {
    if (data === 'fetch-compiler-versions') {
      fetch('https://binaries.soliditylang.org/bin/list.json').then(response => response.json()).then(result => {
        postMessage(result)
      })
    } else {
      importScripts(data.version);            <=== HERE
      const soljson = ctx.Module;

      if ('_solidity_compile' in soljson) {
        const compile = soljson.cwrap('solidity_compile', 'string', ['string', 'number']);
        const output = JSON.parse(compile(data.input))
        postMessage(output)
      }
    }
  });
}

function importScripts(_arg0: string) {
  throw new Error('Function not implemented.'); 
}
rexdavinci commented 1 year ago

Please refer to vuejs dev tools issue#514

ericleponner commented 1 year ago

I did not find root cause of the issue. I worked around by writing my own worker using plain javascript. Thanks for helping.