Skip to content

Commit

Permalink
Set external: true when loading astro config (#11819)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
bluwy and sarah11918 authored Sep 2, 2024
1 parent 560ef15 commit 2bdde80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .changeset/moody-waves-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'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 were able to use Vite features like TypeScript when imported by the Astro config file.

However, this caused confusion as integration authors may test against a package that worked locally, but not when published. This method also restricts using CJS-only dependencies because Vite requires the code to be ESM. Therefore, Astro's behaviour is now changed to ignore processing any type of dependencies by Vite.

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

0 comments on commit 2bdde80

Please sign in to comment.