bfanger / svelte-preprocess-react

Seamlessly use React components inside a Svelte app
MIT License
126 stars 6 forks source link

Unexpected Token? Typescript issues? #21

Closed baradhili closed 1 year ago

baradhili commented 1 year ago

adding preprocessReact to the vanilla SvelteKit (1.0.0) app I get

[vite] Internal server error: /home/bret/Documents/Sites/svelte-test/src/routes/Counter.svelte:10:18 Error while preprocessing /home/bret/Documents/Sites/svelte-test/src/routes/Counter.svelte - Unexpected token
  Plugin: vite-plugin-svelte
  File: /home/bret/Documents/Sites/svelte-test/src/routes/Counter.svelte:10:18
    8 |    $: offset = modulo($displayed_count, 1);
    9 |  
   10 |    function modulo(n: number, m: number) {
                            ^
   11 |      // handle negative numbers
   12 |      return ((n % m) + m) % m;

It seems to be trying to preprocess 'n:' ?

bfanger commented 1 year ago

If you need typescript then the typescript preprocessor should run before the sveltePreprocessReact processor, to do this add the typescript preprocessor as argument:

// svelte.config.js
import preprocess from "svelte-preprocess";
import preprocessReact from "svelte-preprocess-react/preprocessReact";

export default {
  preprocess: preprocessReact({
    preprocess: preprocess({ sourceMap: true }),
  }),
};
baradhili commented 1 year ago

Yup that worked! Thanks