-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node.js subpath import not working #6412
Comments
Sorry, but I don't see any import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
conditions: ['test']
},
plugins: [react()],
test: {
environment: "jsdom",
setupFiles: ["./setupTest.ts"],
},
}); |
I must have confused something, sorry for bothering. Thanks! |
I discovered what was causing the issue and found workaround, and I’m sharing it here for anyone who might encounter the same problem. Initially, I attempted to include the following code within the resolve: {
conditions: ['test']
}, The documentation was a bit misleading for me, as it suggests that the Vite and Vitest configurations share the same structure, which isn’t entirely accurate.
It wasn't until I checked the TypeScript type Here’s the workaround I used: const env = loadEnv(mode, process.cwd(), '')
// ...
resolve: {
conditions: env.VITEST ? ['vitest'] : [],
}, |
@sheremet-va And a question - why vitest does not support |
I don't know what you are talking about. Vitest config is Vite config with a |
Ah, I misunderstood. I thought the “vitest config” referred only to the configs within the |
You can create a separate file called Beware that it does not inherit your |
Describe the bug
I'm encountering an issue where the subpath import specified in package.json with the key 'test' does not seem to work with Vitest. Instead of resolving to the 'test' path, Vitest consistently resolves to the 'default' path.
resolve.conditions = ['test']
to vite.config.NODE_OPTIONS="--conditions=test"
.However, neither of these approaches resolved the issue.
Below is my repro code - I also uploaded my repo link.
In
package.json
, I've defined the subpath import as follows:Here is a simple React component importing
service
:And here is the test code for the component:
Reproduction
https://github.com/JunyeongChoi0/vitest-repro
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: