Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro build ignores cacheDir if outDir is outside project folder #11758

Open
1 task done
EkaanshArora opened this issue Aug 17, 2024 · 2 comments
Open
1 task done

Astro build ignores cacheDir if outDir is outside project folder #11758

EkaanshArora opened this issue Aug 17, 2024 · 2 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@EkaanshArora
Copy link

EkaanshArora commented Aug 17, 2024

Astro Info

Astro                    v3.6.5
Node                     v18.17.0
System                   Linux (x64)
Package Manager          bun
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/tailwind
                         @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I'm trying to use Astro inside an AWS Lambda as a build service tool. I'm using the JS API:

import { build } from "astro";
...
          await build({
            root: path.resolve("/tmp", uniqueDestination),
            outDir: path.resolve("/tmp", "dist", uniqueDestination),
            mode: "production",
            cacheDir: path.resolve("/tmp", "cache", uniqueDestination),
            vite: {
              cacheDir: path.resolve("/tmp", "cache", uniqueDestination),
            },
          });

Since a lambda only has read-only access the build fails as Astro tries to create a .astro directory inside the project folder instead of the specified /tmp dir. Is this a supported use-case? Can I avoid creating the .astro directory in my project folder?

I tried to read through the source and find getOutDirWithinCwd states:

/**
 * Ensures the `outDir` is within `process.cwd()`. If not it will fallback to `<cwd>/.astro`.
 * This is used for static `ssrBuild` so the output can access node_modules when we import
 * the output files. A hardcoded fallback dir is fine as it would be cleaned up after build.
 */

I think this makes sense for most use-cases but fails for being able to use astro inside a read-only directory.

What's the expected result?

Astro uses the specified folder for build cache

Link to Minimal Reproducible Example

https://github.com/EkaanshArora/astro-build-api-cache-repro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 17, 2024
@EkaanshArora EkaanshArora changed the title Astro build ignore cache dir Astro build ignores cacheDir Aug 17, 2024
@EkaanshArora EkaanshArora changed the title Astro build ignores cacheDir Astro build ignores cacheDir if outDir is outside project folder Aug 17, 2024
@florian-lefebvre florian-lefebvre added the needs repro Issue needs a reproduction label Aug 18, 2024
Copy link
Contributor

Hello @EkaanshArora. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Aug 18, 2024
@EkaanshArora
Copy link
Author

@florian-lefebvre florian-lefebvre added needs triage Issue needs to be triaged and removed needs repro Issue needs a reproduction labels Aug 21, 2024
@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants