From bfd67ea749dbc6ffa7c9a671fcc48bea6c04a075 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 9 Mar 2023 16:08:47 -0500 Subject: [PATCH] Remove usage of createRequire in core image (#6488) * Add fallback for hosts without import.meta.url * Try using an import * Add image-size as external * Make image-size external * Apply suggestions from code review * leave image-size alone --- .changeset/lucky-shoes-mate.md | 5 +++++ packages/astro/src/assets/utils/metadata.ts | 4 +--- packages/astro/src/core/sync/index.ts | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changeset/lucky-shoes-mate.md diff --git a/.changeset/lucky-shoes-mate.md b/.changeset/lucky-shoes-mate.md new file mode 100644 index 000000000..32ddde78d --- /dev/null +++ b/.changeset/lucky-shoes-mate.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Remove use of createRequire breaking non-Node hosts. diff --git a/packages/astro/src/assets/utils/metadata.ts b/packages/astro/src/assets/utils/metadata.ts index d1bc37bad..1e96cbe97 100644 --- a/packages/astro/src/assets/utils/metadata.ts +++ b/packages/astro/src/assets/utils/metadata.ts @@ -1,9 +1,7 @@ -import { createRequire } from 'module'; import fs from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { ImageMetadata, InputFormat } from '../types.js'; -const require = createRequire(import.meta.url); -const sizeOf = require('image-size'); +import sizeOf from 'image-size'; export interface Metadata extends ImageMetadata { orientation?: number; diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 914783331..82575f083 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -67,6 +67,7 @@ export async function sync( { server: { middlewareMode: true, hmr: false }, optimizeDeps: { entries: [] }, + ssr: { external: ['image-size'] }, logLevel: 'silent', }, { settings, logging, mode: 'build', command: 'build', fs }