ES6 import

Skip to first unread message

Milan Košir

Feb 28, 2021, 9:31:08 AM2/28/21
to dev
Hi, first of all thank you for this amazing library!
I would like to use it in vitepress project which is built on top of vite, so I'm limited to ES6 imports.
Can somebody give me help how to import hypothesis client library (for my webpage) as ES6 module?
<script src="" async type="module"></script>
doesn't work for me. 
Thank you in advance for any hint!

Milan Košir

Feb 28, 2021, 9:54:12 AM2/28/21
to dev, Milan Košir
I also tried to import hypothesis client in main.js like this:
import './js/hypothesis-client/embed'
but it doesn't work... I think it is because hypothesis has no exports defined.
Thanks for any help, I'm not really js expert, as you can see :)

Milan Košir

Feb 28, 2021, 3:38:46 PM2/28/21
to dev
Just a note: I gave up on importing hypothesis in vitepress.

Robert Knight

Mar 1, 2021, 3:51:32 AM3/1/21
to Milan Košir, dev
Hello Milan,

As you've found out, you can't add Hypothesis to a web page by `import`-ing it. The script is conceptually an application that is run rather than a library that you call. The correct approach is to create an ordinary non-module `<script>` element and add it to the page:

const script = document.createElement('script');
script.src = ''

I don't know anything about Vite or Vitepress, but since you have a `main.js` file where you can execute JavaScript, I would expect you can run something like the above code.

Kind Regards,

You received this message because you are subscribed to the Google Groups "dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Milan Košir

Mar 1, 2021, 11:53:38 AM3/1/21
to Robert Knight, dev
Thank you Robert!
Yes, somehow I understood that from beginning, but wanted to be smart :) 
Vite relies on latest JS functionality straight from the browser (Native-ES-Module), so it's just not compatible with hypothesis.

Maybe "library-fying" your client script would open some new possibilities... but I can't even imagine what it all entails...
Thank you again for this amazing tool!

Best regards to all team,
Reply all
Reply to author
0 new messages