-
This is the error I got. There is a problem with the file path I defined in the "vite.config.ts" file. Can you help me?
import { describe, expect } from "vitest";
import { SetFlags } from "../../src/assets/ts/_utils/ConvertFromDomainToCountryCode.ts";
describe("Convert From Domain To CountryCode", () => {
test("function defined", () => {
expect(SetFlags).toBeDefined();
});
});
import { COUNTRY_INFO } from "@/constant"; //Error this line
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve, dirname } from "node:path";
import vueJsx from "@vitejs/plugin-vue-jsx";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx()
],
resolve: {
alias: {
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
"@": fileURLToPath(new URL("./src", import.meta.url))
}
},
base: "/"
}); SystemOS: macOS 13.2.1 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
I solved this error. I added this code in resolve: {
alias: [{ find: "@", replacement: resolve(__dirname, "./src") }]
} |
Beta Was this translation helpful? Give feedback.
-
@mahmutoz Hi) `///
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I still cannot get this to work with SvelteKit, which generates the aliases in .svelte-kit.tsconfig.json and adds This is my svelte.config.js: import adapter from '@sveltejs/adapter-auto'
import preprocess from 'svelte-preprocess'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const projectRoot = dirname(fileURLToPath(import.meta.url))
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: preprocess({
scss: {
prependData: `@import "${projectRoot}/src/lib/css/sass-mixins.scss";`
},
}),
kit: {
adapter: adapter(),
alias: {
$components: 'src/lib/components',
$stores: 'src/lib/stores',
$types: 'src/lib/types',
$tests: 'tests',
},
},
vitePlugin: {
inspector: true,
},
}
export default config and I can see that the aliases are in .svelte-kit/tsconfig.json. They work fine in Vite, but Vitest continues to ignore them, even with this vite.config.ts: import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vitest/config'
export default defineConfig({
server: {
host: process.env.VITEST ? 'localhost' : '0.0.0.0', // FIXME: this should also be 'localhost' in production
// `npm run dev` should ALWAYS be on port 5173. Tests should NEVER be on this port.
port: process.env.VITEST ? 5174 : 5173,
strictPort: !process.env.VITEST,
},
plugins: [
sveltekit(),
],
test: {
globals: true,
restoreMocks: true,
include: ['tests/unit/**/*.test.{js,ts}'],
environment: 'jsdom',
setupFiles: [
'./vitest.globals.ts',
]
},
}) and this vitest.config.ts: import { defineConfig } from 'vitest/config'
import { mergeConfig } from 'vite'
import viteConfig from './vite.config'
import tsconfigPaths from 'vite-tsconfig-paths'
export default mergeConfig(
viteConfig,
defineConfig({
plugins: [
tsconfigPaths(),
],
})
) What am I doing wrong here? I just want to have the test files, and their ancillaries (like test harnesses and mock stores) in a separate folder from the actual components. It would be so much easier if Vitest could just read the aliases from the Typescript config automatically :) |
Beta Was this translation helpful? Give feedback.
I solved this error. I added this code in
vitest.confic.ts
file.