diff --git a/.changeset/famous-maps-notice.md b/.changeset/famous-maps-notice.md new file mode 100644 index 000000000000..990bc2325787 --- /dev/null +++ b/.changeset/famous-maps-notice.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes installed packages detection when running `astro check` diff --git a/packages/astro/src/cli/install-package.ts b/packages/astro/src/cli/install-package.ts index e7534e77d39a..e732fae7dc1b 100644 --- a/packages/astro/src/cli/install-package.ts +++ b/packages/astro/src/cli/install-package.ts @@ -9,6 +9,8 @@ import prompts from 'prompts'; import whichPm from 'which-pm'; import type { Logger } from '../core/logger/core.js'; +const require = createRequire(import.meta.url); + type GetPackageOptions = { skipAsk?: boolean; optional?: boolean; @@ -24,7 +26,7 @@ export async function getPackage( try { // Try to resolve with `createRequire` first to prevent ESM caching of the package // if it errors and fails here - createRequire(options.cwd ?? process.cwd()).resolve(packageName); + require.resolve(packageName, { paths: [options.cwd ?? process.cwd()] }); const packageImport = await import(packageName); return packageImport as T; } catch (e) {