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

SyntaxError: Unexpected token 'export' #40

Closed
alanhung317 opened this issue Mar 19, 2023 · 5 comments
Closed

SyntaxError: Unexpected token 'export' #40

alanhung317 opened this issue Mar 19, 2023 · 5 comments
Labels
enhancement New feature or request Next.js Issues specific to using tts-react in a Next.js applicaiton.

Comments

@alanhung317
Copy link

Thank you for creating this package!

I ran into this error whenever I refresh/re-render the webpage:
image

The error leads to this:
image

My code:
image

I'm using Next js & the latest tts-react.
image
image

It works again when I hide/unhide my TextToSpeech code, but throws the same error when I refresh the page.

Thank you!

@morganney
Copy link
Owner

Thanks for pointing this issue out.

You are looking for a CJS build which is currently not available, but should be. I'll have to publish a new version of tts-react that includes a CommonJS build.

In the meantime, you can try using transpileModules from Next.js. and add tts-react. Basically you need to convert the import/export's from this package into require/module.exports during your app's build.

@alanhung317
Copy link
Author

Ok! thank you so much!

@alanhung317
Copy link
Author

Just fyi,

I followed the direction to implementing tts-react via Next.js' Module Transpilation.
image

It produced an error of "window is undefined"
image

I then used useEffect and useState to implement the package. It works now. (perhaps there's a better way)
image

@morganney
Copy link
Owner

Since tts-react uses the browser's Web Speech API, you need the standard window checks for Next.js before rendering TextToSpeech or calling useTts. It is not possible to render on the server since the necessary API is not implemented in Node as far as I know.

Your approach seems standard for Next.js apps. You could also load this package dynamically.

@alanhung317
Copy link
Author

Ok, thank you!

@morganney morganney added Next.js Issues specific to using tts-react in a Next.js applicaiton. enhancement New feature or request labels Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Next.js Issues specific to using tts-react in a Next.js applicaiton.
Projects
None yet
Development

No branches or pull requests

2 participants