Skip to content

turborepo, when running sst deploys, leads to env vars not being available to underlying processes #10353

@n-batalha

Description

@n-batalha

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

https://github.com/n-batalha/turbo-repro-issue-10353/blob/main/README-error.md

Which canary version will you have in your reproduction?

2.5.1-canary.1

Environment information

turbo 2.5.1-canary.1

CLI:
   Version: 2.5.1-canary.1
   Path to executable: /Users/nelson/git/REDACTED/node_modules/.pnpm/turbo-darwin-arm64@2.5.1-canary.1/node_modules/turbo-darwin-arm64/bin/turbo
   Daemon status: Running
   Package manager: pnpm9

Platform:
   Architecture: aarch64
   Operating system: macos
   WSL: false
   Available memory (MB): 3845
   Available CPU cores: 12

Environment:
   CI: None
   Terminal (TERM): xterm-ghostty
   Terminal program (TERM_PROGRAM): ghostty
   Terminal program version (TERM_PROGRAM_VERSION): 1.1.3
   Shell (SHELL): /bin/zsh
   stdin: false

Expected behavior

I need to run this command to deploy an app: pnpm exec sst --stage preview deploy, inside an sst app e.g. /app/myapp-infra.

For full context, it deploys an sst app, includes for instance the resource below for a next app:

export const nextjs = new sst.aws.Nextjs("MyApp-Web", {
  path: "./../myapp-web",
  // buildCommand: "pnpm exec open-next build",
  vpc,
  warm: 0,
  link: [relationalDatabase, sourceImagesBucket],
  environment: {
    DB_HOSTNAME: relationalDatabase.host,
    DB_PORT: relationalDatabase.port.apply((v) => String(v)),
    ...
  },
  dev: {
    command: "turbo dev --filter=@workspace/myapp-web...",
    url: "http://localhost:3000/",
  },
});

pnpm exec sst --stage preview deploy works well in the terminal, as well as via pnpm run deploy with package.json having:

  "scripts": {
     ...
    "deploy": "pnpm exec sst --stage preview deploy",
    ...
  },

I would expect turbo run deploy to work too.

Actual behavior

Running turbo run deploy, even with --env-mode=loose, seems to make it such that environment variables are not available during the next app build process.

Unlike pnpm run deploy.

E.g. we edit the next config of the app mentioned above:

// next.config.mjs

import pkg from '@next/env';

const projectDir = process.cwd();
pkg.loadEnvConfig(projectDir);

const { SOME_ENV_FROM_SST } = process.env;

console.log("ENV is: ", SOME_ENV_FROM_SST)

The result is ENV is: undefined. It's correct via pnpm directly.

(by setting SOME_ENV_FROM_SST under environment for the next app config above).

To Reproduce

(covered above)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: reproductionIssues that need a reproduction as requested by the core maintenance team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions