So today I discovered Svelte and I absolutley love the concept. I only got one problem I wrote a small helper.js file and can't seem to import it. Every time I try to reference the class I get
ReferenceError: Helper is not defined
main.js file:
import App from './App.svelte';
import './helper.js';
var app = new App({
target: document.body
});
export default app;
App.svelte file:
<script>
let helper = new Helper();
</script>
<h1>Hello</h1>
helper.js file:
class Helper {
constructor() {
console.log("working");
}
}
So today I discovered Svelte and I absolutley love the concept. I only got one problem I wrote a small helper.js file and can't seem to import it. Every time I try to reference the class I get
ReferenceError: Helper is not defined
main.js file:
import App from './App.svelte';
import './helper.js';
var app = new App({
target: document.body
});
export default app;
App.svelte file:
<script>
let helper = new Helper();
</script>
<h1>Hello</h1>
helper.js file:
class Helper {
constructor() {
console.log("working");
}
}
Share
Improve this question
edited Jul 1, 2019 at 16:28
Dynamicnotion
asked Jul 1, 2019 at 16:23
DynamicnotionDynamicnotion
3131 gold badge2 silver badges7 bronze badges
1 Answer
Reset to default 29You need to import it into the file that uses it:
<script>
import Helper from './helper.js';
let helper = new Helper();
</script>
<h1>Hello</h1>