diff --git a/.changeset/spicy-turkeys-clean.md b/.changeset/spicy-turkeys-clean.md
new file mode 100644
index 000000000000..d417138b1e02
--- /dev/null
+++ b/.changeset/spicy-turkeys-clean.md
@@ -0,0 +1,8 @@
+---
+'astro': patch
+'@astrojs/deno': patch
+'@astrojs/netlify': patch
+---
+
+Alias `from 'astro'` imports to `'@astro/types'`
+Update Deno and Netlify integrations to handle vite.resolves.alias as an array
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index 8270028d4bfe..a3feff5aa4b2 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -96,11 +96,19 @@ export async function createVite(
postcss: astroConfig.style.postcss || {},
},
resolve: {
- alias: {
- // This is needed for Deno compatibility, as the non-browser version
- // of this module depends on Node `crypto`
- randombytes: 'randombytes/browser',
- },
+ alias: [
+ {
+ // This is needed for Deno compatibility, as the non-browser version
+ // of this module depends on Node `crypto`
+ find: 'randombytes',
+ replacement: 'randombytes/browser',
+ },
+ {
+ // Typings are imported from 'astro' (e.g. import { Type } from 'astro')
+ find: /^astro$/,
+ replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)),
+ },
+ ],
},
// Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html)
ssr: {
diff --git a/packages/astro/test/fixtures/type-imports/src/pages/index.astro b/packages/astro/test/fixtures/type-imports/src/pages/index.astro
new file mode 100644
index 000000000000..3577834fbb5f
--- /dev/null
+++ b/packages/astro/test/fixtures/type-imports/src/pages/index.astro
@@ -0,0 +1,19 @@
+---
+import type { MarkdownInstance } from 'astro'
+---
+
+
+
+
+ Astro
+
+
+
+ Astro
+
+
+
diff --git a/packages/astro/test/type-imports.test.js b/packages/astro/test/type-imports.test.js
new file mode 100644
index 000000000000..d420f4eac6e0
--- /dev/null
+++ b/packages/astro/test/type-imports.test.js
@@ -0,0 +1,16 @@
+import { expect } from 'chai';
+import { loadFixture } from './test-utils.js';
+
+describe('Type Imports', async () => {
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({ root: './fixtures/type-imports' });
+ await fixture.build();
+ });
+
+ it('Allows importing types from "astro"', async () => {
+ // if the build passes then the test succeeds
+ expect(true).to.be.true;
+ });
+});
diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts
index 3959e63a842e..aef1f8383655 100644
--- a/packages/integrations/deno/src/index.ts
+++ b/packages/integrations/deno/src/index.ts
@@ -25,8 +25,17 @@ export default function createIntegration(args?: Options): AstroIntegration {
if (target === 'server') {
vite.resolve = vite.resolve || {};
vite.resolve.alias = vite.resolve.alias || {};
- const alias = vite.resolve.alias as Record;
- alias['react-dom/server'] = 'react-dom/server.browser';
+
+ const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
+
+ if (Array.isArray(vite.resolve.alias)) {
+ vite.resolve.alias = [...vite.resolve.alias, ...aliases];
+ } else {
+ for (const alias of aliases) {
+ (vite.resolve.alias as Record)[alias.find] = alias.replacement;
+ }
+ }
+
vite.ssr = {
noExternal: true,
};
diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts
index 843caedc18bd..9b4503e2bb3f 100644
--- a/packages/integrations/netlify/src/integration-edge-functions.ts
+++ b/packages/integrations/netlify/src/integration-edge-functions.ts
@@ -89,8 +89,17 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
if (target === 'server') {
vite.resolve = vite.resolve || {};
vite.resolve.alias = vite.resolve.alias || {};
- const alias = vite.resolve.alias as Record;
- alias['react-dom/server'] = 'react-dom/server.browser';
+
+ const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
+
+ if (Array.isArray(vite.resolve.alias)) {
+ vite.resolve.alias = [...vite.resolve.alias, ...aliases];
+ } else {
+ for (const alias of aliases) {
+ (vite.resolve.alias as Record)[alias.find] = alias.replacement;
+ }
+ }
+
vite.ssr = {
noExternal: true,
};