I use Vite.js with typescript. I have a typescript file in 'src/vmodel/VGraph'. In the index.html, I import the file like this:
<script type="module" src="/src/vmodel/VGraph.ts"></script>
and then later:
<script>
const graph = new VGraph()
</script>
with VGraph defined and declared export
in file above.
ReferenceError: Can't find variable: VGraph
What could be the reason for this?
CodePudding user response:
Modules are accessible only inside js module files so do this instead.
// src/main.ts
import VGraph from './vmodel/VGraph.ts'
const graph = new VGraph()
//....
<script type="module" src="./src/main.ts"></script>