Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __vite_ssr_import_1__.Synth is not a constructor in new Sveltekit project. #1230

Closed
mediashock opened this issue Apr 24, 2024 · 6 comments

Comments

@mediashock
Copy link

Describe the bug
I created a totally new sveltekit project (i tried both v4 and v5 of svelte)
added tone using npm i tone.
imported tone using

import * as Tone from 'tone';
const synth = new Tone.Synth().toDestination();
synth.triggerAttackRelease("C4", "8n");

I get this error
TypeError: vite_ssr_import_1.Synth is not a constructor

@tambien
Copy link
Contributor

tambien commented Apr 30, 2024

I'm not familiar with vite, but just judging by the error, it says vite_ssr_import which might imply server-side rendering. it's possible that Tone.js (since it's designed for the browser) threw an error which stopped the rest of the loading

@yl92
Copy link

yl92 commented May 14, 2024

With 14.9.17 is there any changes to how we should import Tone? This could be the same error, I'm also using import * as Tone from 'tone';.

new Tone.Reverb(c.reverbOptions); // note that this did not raise any error in TypeScript
results in error:
export 'Reverb' (imported as 'Tone') was not found in 'tone' (module has no exports) <- error in the browser

The same code works ok with 14.7.77.

@mediashock
Copy link
Author

I think I have to initialize it inside the onmount. I just switched it to include it from a CDN and everything works but I read onmount is where code should be placed inside a svelte project.

@tambien
Copy link
Contributor

tambien commented May 15, 2024

With 14.9.17 is there any changes to how we should import Tone? This could be the same error, I'm also using import * as Tone from 'tone';.

new Tone.Reverb(c.reverbOptions); // note that this did not raise any error in TypeScript results in error: export 'Reverb' (imported as 'Tone') was not found in 'tone' (module has no exports) <- error in the browser

The same code works ok with 14.7.77.

@yl92 could you try npm i tone@next? There might have been some breaks with the way the package is imported, if that's the case i'll promote the @next version to @latest to hopefully resolve this issue for anyone having it

@yl92
Copy link

yl92 commented May 15, 2024

Thank you @tambien , tone@next worked and there's no longer any errors 🙌

@tambien
Copy link
Contributor

tambien commented May 15, 2024

I think I have to initialize it inside the onmount. I just switched it to include it from a CDN and everything works but I read onmount is where code should be placed inside a svelte project.

Glad you got it working!

@tambien tambien closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants