-
I have
While writing test in FAIL test/utils/index.test.ts [ test/utils/index.test.ts ]
Error: [vite-node] Failed to load ~~/config/constants I guess the problem is vitest not reading |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Is there a way to define paths? |
Beta Was this translation helpful? Give feedback.
-
Using // alias.ts
import { resolve } from 'path'
const r = (p: string) => resolve(__dirname, p)
export const alias: Record<string, string> = {
'~~': r('.'),
'~~/': r('./'),
'@@': r('.'),
'@@/': r('./'),
assets: r('./assets'),
public: r('./public'),
'public/': r('./public/'),
} // vitest.config.ts
import { defineConfig } from 'vite'
import { alias } from './alias'
export default defineConfig({
root: '.',
esbuild: {
tsconfigRaw: '{}',
},
resolve: {
alias,
},
}) |
Beta Was this translation helpful? Give feedback.
Using
alias
in vite config similar totsconfig.json
solves the relative import issue in tests.