I'm building a Chrome extension in Svelte using this boilerplate repo but I'm not sure how to render a Svelte component onto a webpage.
So far I've tried importing the Svelte component into the content script
// src/pages/content/index.ts
import PriceCard from 'src/components/PriceCard.svelte'
const root = document.createElement('div')
const anchor = document.querySelector('.game_area_purchase_game_wrapper')
anchor.insertAdjacentElement('beforebegin', root)
const priceCard = new PriceCard({
target: root
})
export default priceCard
But I get this error: Uncaught SyntaxError: Cannot use import statement outside a module
For reference this is the Svelte component
// src/components/PriceCard.svelte
<script lang='ts'>
let name = 'Joe Bob'
</script>
<main>
<h1>Welcome {name} !</h1>
</main>
The config files (manifest.json
vite.config.ts
, etc) were not altered. I'm using whatever the boilerplate came with.