{"id":17996568,"url":"https://github.com/maxbeatty/repro-vite-env-prefix","last_synced_at":"2026-04-16T17:37:24.571Z","repository":{"id":141081686,"uuid":"464579186","full_name":"maxbeatty/repro-vite-env-prefix","owner":"maxbeatty","description":"Created with CodeSandbox","archived":false,"fork":false,"pushed_at":"2022-02-28T18:23:01.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T17:28:33.244Z","etag":null,"topics":["vite","vitejs"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/github/maxbeatty/repro-vite-env-prefix","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxbeatty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-28T17:28:04.000Z","updated_at":"2022-02-28T18:17:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ce31f65-20b0-4bb3-96f3-72138bed9b00","html_url":"https://github.com/maxbeatty/repro-vite-env-prefix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeatty%2Frepro-vite-env-prefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeatty%2Frepro-vite-env-prefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeatty%2Frepro-vite-env-prefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbeatty%2Frepro-vite-env-prefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbeatty","download_url":"https://codeload.github.com/maxbeatty/repro-vite-env-prefix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128753,"owners_count":20888235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vite","vitejs"],"created_at":"2024-10-29T21:15:01.912Z","updated_at":"2025-10-09T02:49:34.438Z","avatar_url":"https://github.com/maxbeatty.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# repro-vite-env-prefix\nCreated with CodeSandbox\n\n## original problem\n\nwhen trying to introduce [env vars](https://vitejs.dev/guide/env-and-mode.html#env-files) to a project, everything was working great while serving locallly but builds were failing:\n\n\u003cdetails\u003e\n\u003csummary\u003e\n`npm run build` output\n\u003c/summary\u003e\n\n```sh\n❯ npm run build\n\n\u003e vanilla-typescript@1.0.0 build\n\u003e vite build\n\nmode production\nenvDir /Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/config\n{ VITE_APP_TITLE: 'My App (production)' }\nvite v2.8.4 building for production...\n✓ 4 modules transformed.\n[rollup-plugin-dynamic-import-variables] Unexpected token (7:20)\nfile: /Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/src/config.env.ts:7:20\nerror during build:\nSyntaxError: Unexpected token (7:20)\n    at Parser.pp$4.raise (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:19607:13)\n    at Parser.pp$9.unexpected (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:16903:8)\n    at Parser.pp$9.expect (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:16897:26)\n    at Parser.pp$5.parseExprList (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:19474:12)\n    at Parser.pp$5.parseNew (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:19155:57)\n    at Parser.pp$5.parseExprAtom (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:18969:17)\n    at Parser.pp$5.parseExprSubscripts (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:18774:19)\n    at Parser.pp$5.parseMaybeUnary (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:18740:17)\n    at Parser.pp$5.parseExprOps (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:18667:19)\n    at Parser.pp$5.parseMaybeConditional (/Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/node_modules/rollup/dist/shared/rollup.js:18650:19)\n```\n\n\u003c/details\u003e\n\n## solution\n\nit appears the error stems from trying to reference the full name of the environment variable in the error message:\n\n```diff\n- throw new Error('import.meta.env.VITE_APP_TITLE is undefined')\n+ throw new Error('VITE_APP_TITLE is undefined')\n```\n\n`npm run build` now succeeds:\n\n```sh\n❯ npm run build\n\n\u003e vanilla-typescript@1.0.0 build\n\u003e vite build\n\nmode production\nenvDir /Users/mbeatty/Development/src/github.com/maxbeatty/repro-vite-env-prefix/config\n{ VITE_APP_TITLE: 'My App (production)' }\nvite v2.8.4 building for production...\n✓ 5 modules transformed.\ndist/index.html                 0.22 KiB\ndist/assets/index.2dd1a8c1.js   1.16 KiB / gzip: 0.60 KiB\n```\n\nand we can verify that our production value was inlined:\n\n```sh\n❯ grep -q production dist/assets/index.2dd1a8c1.js \u0026\u0026 echo \"found\" || echo \"not found\"\nfound\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbeatty%2Frepro-vite-env-prefix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbeatty%2Frepro-vite-env-prefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbeatty%2Frepro-vite-env-prefix/lists"}