Coder Social home page Coder Social logo

Comments (3)

mass8326 avatar mass8326 commented on June 24, 2024

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.

onsclom avatar onsclom commented on June 24, 2024

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.

lirbank avatar lirbank commented on June 24, 2024

If you remove VERCEL_ENV from dev, then this statement is not true anymore:

image

https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.