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 does not respect vite build/serve commands #10262

Closed
1 task
nmattia opened this issue Feb 28, 2024 · 7 comments · Fixed by #10360
Closed
1 task

Astro does not respect vite build/serve commands #10262

nmattia opened this issue Feb 28, 2024 · 7 comments · Fixed by #10360
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@nmattia
Copy link
Contributor

nmattia commented Feb 28, 2024

Astro Info

Astro                    v4.3.6
Node                     v20.11.1
System                   macOS (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

When astro loads the vite config it does not set the correct command from vite's UserConfig.

For instance, running astro build with a plugin that has apply: "serve" will load the plugin nonetheless.

// vite.config.js
definedConfig({
  plugins: [
    { apply: "serve",  ...somePlugin() }
 ]
});

will apply somePlugin. Same goes with command is read and used instead of apply.

What's the expected result?

Astro should set the correct command when loading the vite config.

NOTE: I could not add a minimal reproducible example because the playground seems broken (errors out on the default example):

~/projects/github-ngr3mk
❯ astro build
ech[callSiteLocation@
depd@
@
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:14872
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:15558
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:13457
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:10539
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:13780
@
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:14872
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:15558
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:13457
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:54:10539
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:189:2456
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:352:378392
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:352:379993
@https://githubngr3mk-ie4y.w-corp-staticblitz.com/blitz.6f234770.js:352:378526]
o
~/projects/github-ngr3mk 1s
❯ echo $?
1

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-ngr3mk

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 Feb 28, 2024
@log101
Copy link
Contributor

log101 commented Mar 4, 2024

It seems like changing the apply property does make a difference. I created this example based on yours. When apply: "build", astro build command works. But when apply: "serve" you get an error as expected.

@bluwy
Copy link
Member

bluwy commented Mar 6, 2024

It's working fine for me: https://stackblitz.com/edit/github-co8sdk. I think we need a proper repro to debug this. It's failing for you @nmattia likely because it's running Astro v0.

@bluwy bluwy added the needs repro Issue needs a reproduction label Mar 6, 2024
Copy link
Contributor

github-actions bot commented Mar 6, 2024

Hello @nmattia. 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 Mar 6, 2024
@nmattia
Copy link
Contributor Author

nmattia commented Mar 7, 2024

@bluwy thanks!

I've tried to reproduce this and turns out it's a slightly different issue. Here is a repro:

// astro.config.ts
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  vite: { /* some vite config, optional */ }
});
// vite.config.ts
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    {
      name: 'a',
      apply: 'serve',
      buildStart() {
        console.log('serve');
      },
    },
  ]
})

If you run npm run build then you'll see that serve is printed to the console. The reason seems to be that if the Astro config is a .ts file (and not /\.[cm]?js$/) then astro will spin up a vite server which will then load serve-style plugins.

This is even more confusing in my case (code not shared) where the vite.config.ts was in a parent directory and Astro should never even have had to read it (I suspect vite's createServer just goes up the directories looking for a vite config).

@bluwy
Copy link
Member

bluwy commented Mar 7, 2024

Thanks! I can repro that now too. I'm not sure why we didn't do it before, but the code you linked should be passing configFile: false so it doesn't load any Vite config files. Feel free to send a PR to fix that!

@bluwy bluwy added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs repro Issue needs a reproduction labels Mar 7, 2024
@nmattia
Copy link
Contributor Author

nmattia commented Mar 7, 2024

@bluwy there you go! #10360

Full disclosure I didn't really manage to get the codespace working (it was running low on resources) and it's my first PR. There might be a bunch of failures & things missing, but hope it helps!

@bluwy
Copy link
Member

bluwy commented Mar 8, 2024

No problem. The changes seem to be good

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

Successfully merging a pull request may close this issue.

3 participants