From 12c2bf871c94d175b29dff34c670b17cfdf7fbec Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 26 Jun 2024 20:57:33 +0800 Subject: [PATCH] Fix getPackage resolve path (#11347) --- .changeset/famous-maps-notice.md | 5 +++++ packages/astro/src/cli/install-package.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/famous-maps-notice.md diff --git a/.changeset/famous-maps-notice.md b/.changeset/famous-maps-notice.md new file mode 100644 index 0000000000..990bc23257 --- /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 e7534e77d3..e732fae7dc 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) {