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

Set external: true when loading astro config #11819

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/moody-waves-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'astro': major
---

Updates the Astro config loading flow to ignore processing locally-linked dependencies with Vite (e.g. `npm link`, in a monorepo, etc). Instead, they will be normally imported by the Node.js runtime the same way as other dependencies from `node_modules`.

Previously, Astro would process locally-linked dependencies, which they were able to use Vite features like TypeScript when imported by the Astro config file. However, it also caused confusion as integration authors may test against a package that worked locally, but not when published. It also restricts using CJS-only dependencies as Vite requires the code to be ESM. Hence, the behaviour is now changed to ignore processing any type of dependencies by Vite.
bluwy marked this conversation as resolved.
Show resolved Hide resolved

In most cases, make sure your locally-linked dependencies are built to JS before running the Astro project, and the config loading should work as before.
15 changes: 1 addition & 14 deletions packages/astro/src/core/config/vite-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ async function createViteServer(root: string, fs: typeof fsType): Promise<ViteDe
optimizeDeps: { noDiscovery: true },
clearScreen: false,
appType: 'custom',
ssr: {
// NOTE: Vite doesn't externalize linked packages by default. During testing locally,
// these dependencies trip up Vite's dev SSR transform. Awaiting upstream feature:
// https://github.com/vitejs/vite/pull/10939
external: [
'@astrojs/tailwind',
'@astrojs/mdx',
'@astrojs/react',
'@astrojs/preact',
'@astrojs/sitemap',
'@astrojs/markdoc',
'@astrojs/db',
],
},
ssr: { external: true },
plugins: [loadFallbackPlugin({ fs, root: pathToFileURL(root) })],
});

Expand Down
Loading