Module unidentified from other script

  javascript, typescript

I was trying access Main from other script in my webpage.
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>

This tells me that

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

You might be wondering what is ‘main’? It is initially Typescript file main.ts, which during compilation is inserted into the webpage’s head.
There is also test.ts, which compiles and is inserted into webpage’s body.

Is there a way to address this?

P.S. The problem with specifying is that src is dynamically changed every time the page is requested, so yeah.

Source: Ask Javascript Questions

LEAVE A COMMENT