user3024710
user3024710

Reputation: 525

Error when using "import" statement in Javascript

I have a following code and get "TypeError: Error resolving module specifier: solc/wrapper" error. I followed these instructions https://github.com/ethereum/solc-js#browser-usage to put the code together.

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="https://solc-bin.ethereum.org/bin/list.js"></script>
	<script type="text/javascript" src="https://solc-bin.ethereum.org/bin/soljson-v0.5.1+commit.c8a2cb62.js"></script>
        <script type="module" defer>
          import * as wrapper from 'solc/wrapper';
        </script>
    </head>
    <body>
    </body>
</html>

Please any suggestions where is the problem? Thank you.

Upvotes: 0

Views: 785

Answers (2)

user3024710
user3024710

Reputation: 525

I have to install solc npm package

npm install solc

in order to make the code running.

Upvotes: 0

wizzwizz4
wizzwizz4

Reputation: 6426

I don't know what the problem was, since I've never seen that ES6 import syntax before, but I fixed it by specifying exactly where to import from:

<!DOCTYPE html>
<html>
    <head>
        <script type="module" defer>
          // debugging
          document.getElementById("runninate").addEventListener("click", function(e){var code=document.getElementById('miniconsole').value; console.log('> ' + code); console.log(eval(code))})

          import * as wrapper from 'https://ethereum.github.io/solc-bin/bin/soljson-v0.5.0-nightly.2018.10.15+commit.b965fd6e.js';
          const solc = wrapper(window.Module);
        </script>
    </head>
    <body>
        <input id="miniconsole" />
        <button id="runninate">Runninate!</button>
    </body>
</html>

I'm not confident enough to say that the syntax was wrong, but considering that they had a typo in the Node.JS example I doubt they tested this.

Note that this fails to import properly because the thing that's being imported doesn't quite work.

Upvotes: 1

Related Questions