无法从其他脚本中识别出模块

时间:2021-07-22 18:59:23

标签: javascript typescript

我试图从我网页中的其他脚本访问 Main。

index.html

<html lang="en">
<head>
<script type="module">
export function Main() {
console.log("Hi!");
}
</script>
</head>
<body>
<script type="module">

import { Main } from "main";
Main();

</script>
</body>
</html>

这告诉我

Uncaught TypeError: Failed to resolve module specifier "main". Relative references must start with either "/", "./", or "../".

您可能想知道什么是“主要”?它最初是 Typescript 文件 main.ts,它在编译期间被插入到网页的头部。 还有test.ts,它编译并插入到网页的正文中。

有没有办法解决这个问题?

附言指定的问题是每次请求页面时都会动态更改 src,所以是的。

0 个答案:

没有答案