gpt4 book ai didi

javascript - 在 Javascript 中使用 "import"语句时出错

转载 作者:行者123 更新时间:2023-12-03 00:32:48 25 4
gpt4 key购买 nike

我有以下代码并收到“TypeError:解析模块说明符时出错:solc/wrapper”错误。我按照这些说明 https://github.com/ethereum/solc-js#browser-usage 进行操作将代码放在一起。

<!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>

请问问题出在哪里?谢谢。

最佳答案

我不知道问题是什么,因为我以前从未见过 ES6 导入语法,但我通过准确指定导入位置来修复它:

<!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>

我没有足够的信心说语法是错误的,但考虑到他们在 Node.JS 示例中存在拼写错误,我怀疑他们对此进行了测试。

请注意,这无法正确导入,因为正在导入的内容无法正常工作。

关于javascript - 在 Javascript 中使用 "import"语句时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53785401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com