diff --git a/packages/vitest/src/integrations/env/index.ts b/packages/vitest/src/integrations/env/index.ts index 3015f9ddb252..07d6fbf530e8 100644 --- a/packages/vitest/src/integrations/env/index.ts +++ b/packages/vitest/src/integrations/env/index.ts @@ -1,6 +1,6 @@ import { pathToFileURL } from 'node:url' import { normalize, resolve } from 'pathe' -import { resolveModule } from 'local-pkg' +import { resolvePath } from 'mlly' import type { BuiltinEnvironment, VitestEnvironment } from '../../types/config' import type { Environment } from '../../types' import node from './node' @@ -40,7 +40,7 @@ export async function loadEnvironment(name: VitestEnvironment, root: string): Pr return environments[name] const packageId = name[0] === '.' || name[0] === '/' ? resolve(root, name) - : resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name) + : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name) const pkg = await import(pathToFileURL(normalize(packageId)).href) if (!pkg || !pkg.default || typeof pkg.default !== 'object') { throw new TypeError( diff --git a/test/env-custom/vitest-environment-custom/package.json b/test/env-custom/vitest-environment-custom/package.json index 62caa1e2b142..634d4cfe70f6 100644 --- a/test/env-custom/vitest-environment-custom/package.json +++ b/test/env-custom/vitest-environment-custom/package.json @@ -1,5 +1,7 @@ { "name": "vitest-environment-custom", "private": true, - "main": "index.mjs" + "exports": { + ".": "./index.mjs" + } }