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

Can't use Env Variables in production build with TS and esbuild.target = "es2018" #16147

Closed
7 tasks done
yojeek opened this issue Mar 12, 2024 · 1 comment · Fixed by #16151
Closed
7 tasks done

Can't use Env Variables in production build with TS and esbuild.target = "es2018" #16147

yojeek opened this issue Mar 12, 2024 · 1 comment · Fixed by #16151

Comments

@yojeek
Copy link

yojeek commented Mar 12, 2024

Describe the bug

When building from TS for production with

    esbuild: {
        target: "es2018",
    },

I'm getting warning [plugin:vite:esbuild] "import.meta" is not available in the configured target environment ("es2018") and will be empty.

So, instead of replacing import.meta.MY_VAR with values from .env file, i've got something like this in dist :

const import_meta = {};
var _a, _b, _c;
const config$1 = {
  API_URL: ((_a = import_meta.env) == null ? void 0 : _a.VITE_API_URL) || "http://localhost:3000",
  GRAPH_API_TYPE: ((_b = import_meta.env) == null ? void 0 : _b.VITE_GRAPH_API) || "filesystem",
  MODE: ((_c = import_meta.env) == null ? void 0 : _c.MODE) === "production" ? "production" : "development"
};

Reproduction

https://stackblitz.com/edit/vue3-vite-typescript-starter-qkcqjq?file=dist%2Fassets%2Findex-DPWZdT5y.js

Steps to reproduce

npm install && npm run build

System Info

See repro.

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Mar 12, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant