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

Uncaught SyntaxError: Unexpected string #47

Closed
BenjaminLesne opened this issue Oct 2, 2023 · 3 comments · Fixed by #63
Closed

Uncaught SyntaxError: Unexpected string #47

BenjaminLesne opened this issue Oct 2, 2023 · 3 comments · Fixed by #63
Labels
bug Something isn't working triage

Comments

@BenjaminLesne
Copy link

I have a react app with the lib mode activated in my vite config.
I use import.meta.env.mode then build the app.
When I use the library in an other app I get :
Uncaught SyntaxError: Unexpected string

reproducible example repo

steps to reproduce:
1- install dependencies

pnpm install

2- build the library :

pnpm build

3- In main.jsx, uncomment line 4 and comment line 3

4- start the dev server

pnpm dev

5- check the console in Chrome
Uncaught SyntaxError: Unexpected string and the webpage shows nothing

Expected behaviour :
The web page displays "yay production" in prod and "not production" in dev mode.

I reproduced it with a Firefox and Chrome.

@davidmyersdev
Copy link
Owner

@BenjaminLesne it looks like this is related to #41. The error is happening because the built library has an object called something like ie.process.env.MODE, and that object is then partially replaced by the plugin as something like ie."development" which is invalid. I still need to come up with a solution, but I have a better idea of the cause now.

@davidmyersdev davidmyersdev added the bug Something isn't working label Oct 14, 2023
@davidmyersdev
Copy link
Owner

I think this static replacement might be the cause.
https://vitejs.dev/guide/env-and-mode.html#production-replacement

@BenjaminLesne
Copy link
Author

@davidmyersdev yeh I saw the Production Replacement thing from vite then I found this

It looks like this related to rollup (see this answer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants