-
Notifications
You must be signed in to change notification settings - Fork 318
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
fix(shared): Preserve import.meta
without requiring ES2020 target
#5203
Conversation
🦋 Changeset detectedLatest commit: 322f1b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
!snapshot |
Hey @wobsoriano - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact |
const text = new TextDecoder().decode(contents); | ||
|
||
// Remove esbuild's var import_meta = {} transformation and restore original import.meta references | ||
const modified = text.replace(/var\s+import_meta\s*=\s*{};/g, '').replace(/import_meta/g, 'import.meta'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This restores the original import.meta
references
Example built file:

without the plugin and ES2020 target, it gets transformed to:
var import_meta = {};
// ... other code
if (typeof import_meta !== "undefined" && import_meta.env && typeof import_meta.env[name] === "string") {
return import_meta.env[name];
}
@@ -0,0 +1,5 @@ | |||
--- | |||
"@clerk/shared": minor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're removing the target...
Closing this as we want to keep the state of the shared package and fix the issue in clerk-js side instead |
Description
In #4985, we introduced a shared function that checks if environment variables exist across different platforms (Node.js, Vite, Cloudflare, etc). To support Vite's
import.meta.env
, we set the build target toES2020
, but this broke support for older browsers due to ES2020 features like optional chaining.This PR removes the added ES2020 target, but preserves the
import.meta
functionality via a plugin. The plugin removes esbuild'svar import_meta = {}
transformation and restores the originalimport.meta
references in ESM builds only, while maintaining compatibility with older browsers.Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change