这是indexloc提供的服务,不要输入任何密码
Skip to content

Caching environment variables on Vercel #401

@lukebussey

Description

@lukebussey

What version of Turborepo are you using?

1.0.19

Describe the Bug

On Vercel I have a public environment variable set called NEXT_PUBLIC_SEGMENT_WRITE_KEY. It's set to one value for production, and another for preview and development.

If I deploy a preview branch with the build command set to cd ../.. && yarn turbo run build --scope=website --includeDependencies --no-deps and preview the site, the correct env var for preview/dev used.

But then if I then do a production deployment, the env var for preview/dev is still used. The env var is used within a function, within a component like this:

  const renderSnippet = () => {
    const opts = {
      apiKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY,
      load: true,
      page: true,
    };

    if (!opts.apiKey) {
      return null;
    }

    return snippet.min(opts);
  };

Clearing the build command so it's just the Next.js default restores the normal behaviour.

Expected Behavior

Correct production env var is picked up and used.

To Reproduce

  1. Create a public environment variable with different values for production and preview/development.
  2. Render process.env.NEXTJS_PUBLIC_<var name> to page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions