sanity icon indicating copy to clipboard operation
sanity copied to clipboard

`sanity start` command uses incorrect .env file

Open joecritch opened this issue 3 years ago • 4 comments

Describe the bug

I have both a .env.production and .env.development inside my local studio folder (for sanity deploy and sanity start respectively), both containing custom SANITY_STUDIO_ environment variables. However, when I just run sanity start command, it uses the SANITY_STUDIO_ variables from .env.production file instead of .env.development.

  • Note 1: if I delete the local .env.production, sanity start then works as expected.
  • Note 2: if I use a more explicit SANITY_ACTIVE_ENV=development sanity start, then it works as expected

To Reproduce

  1. Create both .env.production and .env.development each with a custom variable of different values, e.g. SANITY_STUDIO_PROJECT_URL
  2. Log the value out in (in resolveProductionUrl.js's function for example)
  3. Run sanity start
  4. Note how it will show the SANITY_STUDIO_PROJECT_URL from .env.production, as opposed to .env.development

Expected behavior

I expect to see the values from .env.development when running sanity start, in accordance to the docs: "If not defined, it will default to development when running the sanity start command".

Which versions of Sanity are you using?

@sanity/cli                 2.6.0 (up to date)
@sanity/base                2.6.0 (up to date)
@sanity/components          2.2.6 (up to date)
@sanity/core                2.6.1 (up to date)
@sanity/dashboard           2.2.6 (up to date)
@sanity/default-layout      2.6.0 (up to date)
@sanity/default-login       2.2.6 (up to date)
@sanity/desk-tool           2.6.1 (up to date)
@sanity/google-maps-input   2.6.0 (up to date)
@sanity/production-preview  2.2.6 (up to date)
@sanity/vision              2.2.6 (up to date)

What operating system are you using?

macOS Catalina (10.15.7)

Which versions of Node.js / npm are you running?

npm: 7.6.1
node: v12.16.3

joecritch avatar Mar 12 '21 20:03 joecritch

I'm also having this issue. @2.7.4

darenmalfait avatar Apr 02 '21 17:04 darenmalfait

What actually happens is that it uses both the .production AND .development files (the second of which always overwrites the first one). Certainly seems like a bug and the workaround is to explicitly set SANITY_ACTIVE_ENV in every case.

alexcodito avatar Aug 26 '21 10:08 alexcodito

I am also having this issue, but in the opposite. I have an .env.development with a localhost setup, and an .env.production with a production domain setup. When I run sanity deploy and visit the xxx.studio app, my Preview links are all pointing at localhost.

I can confirm @alexcodito's workaround fixes this

jcontonio avatar Mar 21 '22 17:03 jcontonio

I am having the same issue as @jcontonio. It would be really nice if this can be fixed in the next releases.

LeonSkrilec avatar Jul 14 '22 08:07 LeonSkrilec

Hi!

We are currently working on improving our workflows and follow-up on our open GitHub repository. In that work, we have decided to close most issues older than the release of Sanity Studio v3.

We value your feedback, so if this issue is still important to you and relevant for Sanity Studio v3, please search for relevant open issues. If you can’t find any, open a new one and link to relevant comments in this thread. For questions about how to do something, please post them in the slack community.

kmelve avatar Jan 12 '23 18:01 kmelve