vitejs / vite-plugin-vue

Vite Vue Plugins
MIT License
502 stars 155 forks source link

Exporting vite config with UserConfigFnObject type build error #384

Closed rom-sky-blue closed 7 months ago

rom-sky-blue commented 7 months ago

Related plugins

Describe the bug

I created the following configuration file with reference to the following document in order to use environment variables in the configuration. https://vitejs.dev/config/

vite.config.ts

/// <reference types="vitest" />

import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    // vite の設定
    plugins: [vue(), vueJsx()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    test: {
      globals: true,
    },
    server: {
      proxy: {
        '/api': {
          target: env.VITE_API_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace('/api', ''),
        },
      },
    },
  };
});

It appears to work fine in development mode, but I get the following TypeScritpt error when I build

vitest.config.ts:6:3 - error TS2345: Argument of type 'UserConfigFnObject' is not assignable to parameter of type 'never'.

The same error occurs when I format it as shown in the following post. https://github.com/vitejs/vite/issues/13950

Reproduction

https://stackblitz.com/edit/vitejs-vite-osther?file=index.html&terminal=dev

Steps to reproduce

Only build script make

System Info

yarn create vue@5.0.10

Used Package Manager

yarn

Logs

No response

Validations

github-actions[bot] commented 7 months ago

Hello @rom-sky-blue. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.