Comments (3)
Running into this as well using SvelteKit!
Environment variables are statically replaced when imported from $env/static/private
and $env/static/public
, so I was no longer able to build.
My solution for now is to create a .env
file next to the .env.local
file that vercel env pull
generates. This is because SvelteKit uses Vite and its cascading env files. Fill it with placeholder values for whatever variables you need, check it into git, and then you're good to go.
You can alternatively make a .env.development
specifically for svelte-check
and a .env.production
for vite build
.
from vercel.
I'm sorry this broke your builds! Can you tell me more about how you depend on VERCEL_ENV
? Could you manually create your own environment variables and use those to accomplish the same things?
My thinking is that it is more consistent to just not have any system environment variables in local dev. Most of them have meaningless values, and the ones that do have meaningful values can be replicated through other means.
from vercel.
If you remove VERCEL_ENV from dev, then this statement is not true anymore:
![image](https://private-user-images.githubusercontent.com/2538130/335832177-48382b55-166f-47c6-981d-775b5910c22b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc0MDE5MDIsIm5iZiI6MTcxNzQwMTYwMiwicGF0aCI6Ii8yNTM4MTMwLzMzNTgzMjE3Ny00ODM4MmI1NS0xNjZmLTQ3YzYtOTgxZC03NzViNTkxMGMyMmIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYwMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MDNUMDgwMDAyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjZmM2RmZWEyMTljYjcxZTkwOWI4MzU2ZWVlNzZlYjI0YmRlYTlmOWE0Y2RlYmM3YjgwY2Q5NTRjMjkzZTdmMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.I655Y2DPupP5kqVKurPKYwAOoQKS9v08t7dEvjwuwB4)
There are ways to work around it, I am just pointing out that it's a breaking change since the docs say it will be either of those three values.
Here is one of many example of how we use it:
// https://vercel.com/docs/projects/environment-variables/system-environment-variables
const production = "https://example.com"; // The production domain
const development = "http://localhost:3000";
const preview = `https://${process.env.VERCEL_URL}`;
export function getOrigin() {
if (process.env.VERCEL_ENV === "production") {
return new URL(production).origin;
}
if (process.env.VERCEL_ENV === "development") {
return new URL(development).origin;
}
if (process.env.VERCEL_ENV === "preview") {
return new URL(preview).origin;
}
// This should never happen
throw new Error("Unknown origin");
}
In this example, I can just rearrange the code so that it falls back to development. But I need to think it through thoroughly, what if it is in CI/test mode? With the code as-is, I know it will barf if I screw up the test runner config etc.
Another use case is that we want to use a local Postgres DB for dev, which uses a different driver than Vercel Postgres or Neon Postgres, so we check VERCEL_ENV to use the right driver depending in environment. Again, I can change the code, but you are breaking a lot of stuff by removing the VERCEL_ENV for dev.
I think it is really convenient to have VERCEL_ENV available, as a complement to NODE_ENV. I think it is a mistake to remove it for dev.
from vercel.
Related Issues (20)
- Latest NextJs build error HOT 1
- getInstalledPackageVersion is not a function HOT 3
- [email protected]
- Attempting to build locally with pnpm install does not work
- Error when adding new domain to the project
- [vc dev] `tsconfig.json` setting `verbatimModuleSyntax` and `module: preserve` not allowed
- Function runtime error: Cannot find module HOT 2
- vercel dev not working HOT 2
- Latest version of cli is pulling in insecure packages that have available patches HOT 3
- Python runtime does not work on Python 3.12 with ASGI HOT 11
- [34.1.8] `vercel build` Error: Cannot read properties of null (reading 'trim') HOT 5
- Automatic updates for Go releases
- Bug: Parallel intercepted route in Next.js
- Regression: `vercel build` fails with pnpm v9.1.x on latest Vercel CLI HOT 16
- Console Logs Merging into a Single Message in Dashboard when Using ESModules
- ERROR: @rollup/rollup-linux-x64-gnu not found for serverless function running on Vercel HOT 3
- The Starlette lifespan async context manager is not executed
- I am tryping to deploy my web project on vercel
- Not able to apply custom timeline for my project logs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vercel.