aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.23k stars 44 forks source link

TypeScript types doesn't seem to be compatible in `vite.config.ts` with `defineConfig()` API #105

Closed caldwell-63 closed 1 year ago

caldwell-63 commented 1 year ago

image

// vite.config.ts
import { defineConfig } from 'vite';
import vtscp from 'vite-tsconfig-paths';

export default defineConfig({
  plugins: [
    vtscp()
  ]
});

"vite-tsconfig-paths": "^4.0.7" "typescript": "^4.9.3", "vite": "^4.2.0"

Type 'Plugin_2' is not assignable to type 'PluginOption'.
  Type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").Plugin' is not assignable to type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").Plugin'.
    Types of property 'apply' are incompatible.
      Type '"build" | "serve" | ((this: void, config: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").ConfigEnv) => boolean) | undefined' is not assignable to type '"build" | "serve" | ((this: void, config: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").ConfigEnv) => boolean) | undefined'.
        Type '(this: void, config: UserConfig, env: ConfigEnv) => boolean' is not assignable to type '"build" | "serve" | ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | undefined'.
          Type '(this: void, config: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").ConfigEnv) => boolean' is not assignable to type '(this: void, config: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").ConfigEnv) => boolean'.
            Types of parameters 'config' and 'config' are incompatible.
              Type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig' is not assignable to type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig'.
                Types of property 'plugins' are incompatible.
                  Type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption[] | undefined' is not assignable to type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption[] | undefined'.
                    Type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption[]' is not assignable to type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption[]'.
                      Type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption' is not assignable to type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption'.
                        Type 'Plugin_2' is not assignable to type 'PluginOption'.
                          Type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").Plugin' is not assignable to type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").Plugin'.
                            Types of property 'apply' are incompatible.
                              Type '"build" | "serve" | ((this: void, config: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").ConfigEnv) => boolean) | undefined' is not assignable to type '"build" | "serve" | ((this: void, config: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").ConfigEnv) => boolean) | undefined'.
                                Type '(this: void, config: UserConfig, env: ConfigEnv) => boolean' is not assignable to type '"build" | "serve" | ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | undefined'.
                                  Type '(this: void, config: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").ConfigEnv) => boolean' is not assignable to type '(this: void, config: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig, env: import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").ConfigEnv) => boolean'.
                                    Types of parameters 'config' and 'config' are incompatible.
                                      Type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").UserConfig' is not assignable to type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").UserConfig'.
                                        Types of property 'plugins' are incompatible.
                                          Type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption[] | undefined' is not assignable to type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption[] | undefined'.
                                            Type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption[]' is not assignable to type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption[]'.
                                              Type 'import("/home/konr/@caldwell-63/web/node_modules/vite/dist/node/index").PluginOption' is not assignable to type 'import("/home/konr/@caldwell-63/web/packages/apps/pxdna/node_modules/vite/dist/node/index").PluginOption'.
                                                Type 'PluginOption[]' is not assignable to type 'PluginOption'.ts(2322)
aleclarson commented 1 year ago

Is v4.0.7 the first version to exhibit this error?

Are you sure it's the fault of this plugin and not a Vite version mismatch between packages in your monorepo?

lensbart commented 1 year ago

Now it seems to work on my end, with

"typescript": "^5.0.4",
"vite": "^4.2.1",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.30.1"
drob commented 2 days ago

I'm running into the same compilation error with these:

    "typescript": "^5.5.2",
    "vite-tsconfig-paths": "^4.3.2",
    "vitest": "^1.6.0"

So I suspect the issue might be elsewhere in the config than in the specific package versions.