Skip to content

Commit

Permalink
Remove usage of createRequire in core image (#6488)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matthewp authored Mar 9, 2023
1 parent dbd61c1 commit bfd67ea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-shoes-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove use of createRequire breaking non-Node hosts.
4 changes: 1 addition & 3 deletions packages/astro/src/assets/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit bfd67ea

Please sign in to comment.