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

Defaults for define in main are causing esbuild error due to process.env not being a valid value #5

Closed
4 tasks done
kskalski opened this issue Jun 4, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@kskalski
Copy link

kskalski commented Jun 4, 2022

Describe the bug

I'm getting error

> error: Invalid define value (must be valid JSON syntax or a single identifier): process.env

 > error: Invalid define value (must be valid JSON syntax or a single identifier): global.process.env

 > error: Invalid define value (must be valid JSON syntax or a single identifier): globalThis.process.env

which can be bypassed by adding define, that replaces those keys with something else like single identifier or {}. However for main process I do actually want to use process.env, which appears to be not possible to do now (I suspect newest esbuild introduced some stricter checks that the value is single identifier or valid JSON, but process.env is neither, see evanw/esbuild#2292).

I think for main section we shouldn't actually use the define at all, since we are replacing process.env with process.env, which doesn't make a lot of sense and those references could be left as they are in the emitted code.

Electron-Vite Version

1.0.3

Electron Version

18

Vite Version

v3.0.0-alpha.8

Validations

@kskalski kskalski added the bug Something isn't working label Jun 4, 2022
@alex8088
Copy link
Owner

alex8088 commented Jun 5, 2022

@kskalski

I can't reproduce this bug (esbuild ver: 0.14.42). Can you provide more detailed info on this?

In Vite, the string replacement is done by itself, the define config should not be used in esbuild. see vite define plugin

@kskalski
Copy link
Author

kskalski commented Jun 6, 2022

Ok, seems like this error happens only when I remove

 external: ['@electron-toolkit/utils']

line in the config. I was building without this external declaration, because I wasn't sure for its need, but possibly it shouldn't be ever removed.

kskalski added a commit to kskalski/electron-vite-boilerplate that referenced this issue Jun 8, 2022
@kskalski
Copy link
Author

kskalski commented Jun 8, 2022

Well, adding toolkit/utils to my larger project didn't fix the issue, but it does make a difference in electron-vite-boilerplate project. I created reproduction in https://github.com/kskalski/electron-vite-boilerplate

Note that it uses the alpha version of vite (which currently is conflictinhg with electron-vite's deps, thus the override flag in npm install).

I was able to workaround the problem in my project by commenting out contents of

'process.env': `process.env`,

so the real question is if those defines are some kind of obsolete feature, do we still need it in the plugin.

@alex8088
Copy link
Owner

alex8088 commented Jun 9, 2022

@kskalski Thanks for taking the time to reproduce the issue. I will try it too. Whether this feature is still needed, we should really think about it 🤔 .

@alex8088
Copy link
Owner

use vite@3 now

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

No branches or pull requests

2 participants