aleclarson / vite-tsconfig-paths

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

Type 'Plugin_2' is not assignable to type 'PluginOption'. #122

Closed dardino closed 1 year ago

dardino commented 1 year ago

I get an error in vite config when importing this plugin:

versions (in package.json):

{
    "@types/react": "^18.2.14",
    "@types/react-dom": "^18.2.6",
    "@typescript-eslint/eslint-plugin": "^5.61.0",
    "@typescript-eslint/parser": "^5.61.0",
    "@vitejs/plugin-react-swc": "^3.3.2",
    "cypress": "^12.16.0",
    "cypress-visual-regression": "^3.0.0",
    "eslint": "^8.44.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.1",
    "typescript": "^5.1.6",
    "vite": "^4.4.0"
}

vite.config.ts:

import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import viteTsconfigPaths from "vite-tsconfig-paths";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(), 
    viteTsconfigPaths()  // <-- ERROR Type 'Plugin_2' is not assignable to type 'PluginOption'.
  ],
});

extended error:

Type 'Plugin_2' is not assignable to type 'PluginOption'.
  Type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").Plugin' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").Plugin'.
    Types of property 'apply' are incompatible.
      Type '"build" | "serve" | ((this: void, config: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").ConfigEnv) => boolean)' is not assignable to type '"build" | "serve" | ((this: void, config: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").ConfigEnv) => boolean)'.
        Type '(this: void, config: UserConfig, env: ConfigEnv) => boolean' is not assignable to type '"build" | "serve" | ((this: void, config: UserConfig, env: ConfigEnv) => boolean)'.
          Type '(this: void, config: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").ConfigEnv) => boolean' is not assignable to type '(this: void, config: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").ConfigEnv) => boolean'.
            Types of parameters 'config' and 'config' are incompatible.
              Type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig'.
                Types of property 'plugins' are incompatible.
                  Type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption[]' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption[]'.
                    Type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption'.
                      Type 'Plugin_2' is not assignable to type 'PluginOption'.
                        Type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").Plugin' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").Plugin'.
                          Types of property 'apply' are incompatible.
                            Type '"build" | "serve" | ((this: void, config: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").ConfigEnv) => boolean)' is not assignable to type '"build" | "serve" | ((this: void, config: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").ConfigEnv) => boolean)'.
                              Type '(this: void, config: UserConfig, env: ConfigEnv) => boolean' is not assignable to type '"build" | "serve" | ((this: void, config: UserConfig, env: ConfigEnv) => boolean)'.
                                Type '(this: void, config: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").ConfigEnv) => boolean' is not assignable to type '(this: void, config: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig, env: import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").ConfigEnv) => boolean'.
                                  Types of parameters 'config' and 'config' are incompatible.
                                    Type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").UserConfig' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").UserConfig'.
                                      Types of property 'plugins' are incompatible.
                                        Type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption[]' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption[]'.
                                          Type 'import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption' is not assignable to type 'import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption'.
                                            Type 'Promise<false | Plugin_2 | PluginOption[]>' is not assignable to type 'PluginOption'.
                                              Type 'Promise<false | import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").Plugin | import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption[]>' is not assignable to type 'Promise<false | import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").Plugin | import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption[]>'.
                                                Type 'false | import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").Plugin | import("/home/currentuser/dev/my-apps/web_new/node_modules/vite/dist/node/index").PluginOption[]' is not assignable to type 'false | import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").Plugin | import("/home/currentuser/dev/my-apps/web_new/webapp/node_modules/vite/dist/node/index").PluginOption[]'.
                                                  Type 'Plugin_2' is not assignable to type 'false | Plugin_2 | PluginOption[]'.ts(2322)
aleclarson commented 1 year ago

Looks like incompatible versions of Vite in my-apps/web_new/webapp/node_modules and my-apps/web_new/node_modules