From d7fa5cde6f270c66392b74a848b1eb2c178a2304 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 25 Apr 2024 11:19:50 +0200 Subject: [PATCH] docs: add a warning about aliasing (#5618) --- docs/config/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/config/index.md b/docs/config/index.md index a207e6095..c5f888c90 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -318,6 +318,14 @@ To provide object via CLI command, use the following syntax: `--outputFile.json= Define custom aliases when running inside tests. They will be merged with aliases from `resolve.alias`. +::: warning +Vitest uses Vite SSR primitives to run tests which has [certain pitfalls](https://vitejs.dev/guide/ssr.html#ssr-externals). + +1. Aliases affect only modules imported directly with an `import` keyword by an [inlined](#server-deps-inline) module (all source code is inlined by default). +2. Vitest does not support aliasing `require` calls. +3. If you are aliasing an external dependency (e.g., `react` -> `preact`), you may want to alias the actual `node_modules` packages instead to make it work for externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.io/aliases/) support aliasing via the `npm:` prefix. +::: + ### globals - **Type:** `boolean` -- 2.51.2