Home > Net >  Class not visible
Class not visible

Time:07-10

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.

I get the error message: enter image description here

ReferenceError: Can't find variable: VGraph

What could be the reason for this?

The file seems to be loaded: enter image description here

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>
  • Related