Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/busy-pandas-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'astro': patch
---

Fixes an error that could occur after the dev server restarts when using an adapter such as `@astrojs/cloudflare`, where a request would fail with a `500` referencing a missing pre-bundled dependency:

```
The file does not exist at "node_modules/.vite/deps_ssr/astro_compiler-runtime.js?v=6419660d" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
```
12 changes: 12 additions & 0 deletions .changeset/loose-tables-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@astrojs/cloudflare': patch
'@astrojs/markdoc': patch
'@astrojs/netlify': patch
'@astrojs/svelte': patch
'@astrojs/vercel': patch
'@astrojs/node': patch
'@astrojs/mdx': patch
'@astrojs/vue': patch
---

Fixes an issue where the `peerDependencies` field used incorrect dependencies.
7 changes: 6 additions & 1 deletion packages/astro/src/vite-plugin-astro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export default function astro({ settings, logger }: AstroPluginOptions): vite.Pl
viteConfig.resolve.conditions = [...defaultServerConditions];
}
}
viteConfig.resolve.conditions.push('astro');
// `configEnvironment` can run again on dev server restart with the
// resolved `conditions` carried over, so only add `astro` if missing to
// avoid a duplicate that changes the optimizeDeps config hash.
if (!viteConfig.resolve.conditions.includes('astro')) {
viteConfig.resolve.conditions.push('astro');
}
},
async configResolved(viteConfig) {
const toolbarEnabled = await settings.preferences.get('devToolbar.enabled');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type * as vite from 'vite';
import { defaultClientConditions } from 'vite';
import astro from '../../../dist/vite-plugin-astro/index.js';
import { createBasicSettings, defaultLogger } from '../test-utils.ts';

function getConfigEnvironmentHook(plugins: vite.Plugin[]) {
const plugin = plugins.find((p) => p.name === 'astro:build');
const hook = plugin?.configEnvironment;
return typeof hook === 'function' ? hook : hook?.handler;
}

describe('vite-plugin-astro configEnvironment', () => {
it('adds the `astro` resolve condition exactly once across repeated calls', async () => {
const settings = await createBasicSettings();
const configEnvironment = getConfigEnvironmentHook(astro({ settings, logger: defaultLogger }));
assert.equal(typeof configEnvironment, 'function');

// On dev server restart, `configEnvironment` runs again and the resolved
// `resolve.conditions` array carries over. Calling it twice on the same
// config must not duplicate the `astro` condition, otherwise the
// environment's optimizeDeps config hash changes and forces a spurious
// dependency re-optimization.
const viteConfig: vite.EnvironmentOptions & { consumer?: string } = {
consumer: 'client',
resolve: {},
};
await configEnvironment!.call({} as any, 'client', viteConfig as any, {} as any);
await configEnvironment!.call({} as any, 'client', viteConfig as any, {} as any);

assert.deepEqual(viteConfig.resolve!.conditions, [...defaultClientConditions, 'astro']);
});
});
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"vite": "^8.0.13"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.2",
"astro": "^7.0.0",
"wrangler": "^4.83.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"htmlparser2": "^10.1.0"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.0"
"astro": "^7.0.0"
},
"devDependencies": {
"@types/markdown-it": "^14.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"vfile": "^6.0.3"
},
"peerDependencies": {
"@astrojs/markdown-satteri": "^0.3.1-alpha.0",
"astro": "^7.0.0-alpha.0"
"@astrojs/markdown-satteri": "^0.3.1",
"astro": "^7.0.0"
},
"peerDependenciesMeta": {
"@astrojs/markdown-satteri": {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"vite": "^8.0.13"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.0"
"astro": "^7.0.0"
},
"devDependencies": {
"@types/node": "^22.10.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"server-destroy": "^1.0.1"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.2"
"astro": "^7.0.0"
},
"devDependencies": {
"@fastify/middie": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"svelte": "^5.54.1"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.0",
"astro": "^7.0.0",
"svelte": "^5.43.6",
"typescript": "^5.3.3 || ^6.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"tinyglobby": "^0.2.15"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.0"
"astro": "^7.0.0"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"vue": "^3.5.30"
},
"peerDependencies": {
"astro": "^7.0.0-alpha.0",
"astro": "^7.0.0",
"vue": "^3.5.24"
},
"engines": {
Expand Down
Loading