electron-svelte-typescript icon indicating copy to clipboard operation
electron-svelte-typescript copied to clipboard

Question: What do I need to change to import TS files into a Svelte component?

Open SkepticMystic opened this issue 3 years ago • 1 comments

Thank you for making this template, it simplifies the process so much!

I have a question that may be simple to solve, or I may be misunderstanding something more fundamental.

I want to import a function from a TS file into the App svelte component from your template. The function uses the Twitter v2 API, so that might be causing an issue. I use the following code to import the function into App:

<script lang="ts">
  import { getUserDesc } from "../electron/utils/Twitter/twitter";
  export let name: string;
</script>

Where the twitter.ts file looks like so:

import TwitterApi from 'twitter-api-v2';

const twitter = new TwitterApi()

const roClient = twitter.readOnly

export async function getUserDesc(username: string) {
    const user = await roClient.v2.userByUsername(username)
    console.log(user.data.description)
}

When running the code, I get the following error: Error: Unexpected token (Note that you need plugins to import files that are not JavaScript).

Is it that I just need a rollup-plugin? Please let me know if there is something to do differently.

Thank you for reading this :)

SkepticMystic avatar Jan 25 '22 07:01 SkepticMystic

Thanks for using the template!

I see that there was an issue here https://github.com/rollup/plugins/issues/287.

I cannot reproduce this on Linux or macos.

fuzzc0re avatar Jan 25 '22 08:01 fuzzc0re