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

Update serializeDefine implementation from upstream vite #193

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

vasiliicuhar
Copy link
Contributor

@vasiliicuhar vasiliicuhar commented May 31, 2024

This PR updates serializeDefine to latest version from vite. It fixes compilation errors when define contains string values.

[vite:define] Transform failed with 1 error:
error: Invalid define value (must be an entity name or valid JSON syntax)

For some unknown reasons it's not working only in combination with @vitejs/plugin-react, however, the issue is with (${val}) syntax, that esbuild doesn't accept.

Environment

node@18.18.2
vite@^5.2.12
vite-plugin-web-extension@4.1.3
@vitejs/plugin-react@^4.3.0

Sample config

export default defineConfig({
  define: {
    "process.env.REACT_APP_BASEURL": '""'
  },
  plugins: [
    react(),
    webExtension({
      manifest: generateManifest,
    }),
  ]
})

@aklinker1
Copy link
Owner

aklinker1 commented Jun 3, 2024

Interesting, must have broken on some new version of vite? Last I checked, you still had to define string constants like so '"some text"', and JSON.stringify did that for you...

That and skipping the final comma seen to be the only changes?

Copy link
Owner

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I see. This is for define.__DEFINES__ not define. That makes sense. Thanks for the PR, I'll get this deployed!

@aklinker1 aklinker1 merged commit 088e074 into aklinker1:main Jun 4, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants