cmseguin / rollup-plugin-react-scoped-css

A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)
43 stars 6 forks source link

TypeScript error in Vite config #60

Open aae-gwhitehorn opened 3 months ago

aae-gwhitehorn commented 3 months ago

When I add this to the plugins array, I get the following error from eslint on the export default line:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '({ command, mode }: ConfigEnv) => { define: { __APP_ENV__: string; }; plugins: (PluginOption[] | Plugin<any> | VitePartialPlugin[])[]; resolve: { alias: { ...; }; }; server: { ...; }; build: { ...; }; test: { ...; }; }' is not assignable to parameter of type 'UserConfigExport'.
      Type '({ command, mode }: ConfigEnv) => { define: { __APP_ENV__: string; }; plugins: (PluginOption[] | Plugin<any> | VitePartialPlugin[])[]; resolve: { alias: { ...; }; }; server: { ...; }; build: { ...; }; test: { ...; }; }' is not assignable to type 'UserConfigFnObject'.
        Call signature return types '{ define: { __APP_ENV__: string; }; plugins: (PluginOption[] | Plugin<any> | VitePartialPlugin[])[]; resolve: { alias: { '@': string; }; }; server: { hmr: { host: string; }; host: true; port: number; strictPort: true; watch: { ...; }; }; build: { ...; }; test: { ...; }; }' and 'UserConfig' are incompatible.
          The types of 'plugins' are incompatible between these types.
            Type '(PluginOption[] | Plugin<any> | VitePartialPlugin[])[]' is not assignable to type 'PluginOption[]'.
              Type 'PluginOption[] | Plugin<any> | VitePartialPlugin[]' is not assignable to type 'PluginOption'.
                Type 'VitePartialPlugin[]' is not assignable to type 'PluginOption'.
                  Type 'VitePartialPlugin[]' is not assignable to type 'PluginOption[]'.
                    Type 'VitePartialPlugin' is not assignable to type 'PluginOption'.
                      Type 'VitePartialPlugin' is not assignable to type 'Plugin<any>'.
                        Types of property 'load' are incompatible.
                          Type 'ObjectHook<(this: PluginContext, id: string) => LoadResult | Promise<LoadResult>, {}>' is not assignable to type 'ObjectHook<(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise<LoadResult>>'.
                            Type '(this: PluginContext, id: string) => LoadResult | Promise<LoadResult>' is not assignable to type 'ObjectHook<(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise<LoadResult>>'.
                              Type '(this: PluginContext, id: string) => LoadResult | Promise<LoadResult>' is not assignable to type '(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise<LoadResult>'.
                                Type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").LoadResult | Promise<import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").LoadResult>' is not assignable to type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").LoadResult | Promise<import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").LoadResult>'.
                                  Type 'SourceDescription' is not assignable to type 'LoadResult | Promise<LoadResult>'.
                                    Type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").SourceDescription' is not assignable to type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").SourceDescription'.
                                      Types of property 'ast' are incompatible.
                                        Type 'AstNode' is not assignable to type 'ProgramNode'.
                                          Type 'AstNode' is missing the following properties from type 'Omit<Program, OmittedEstreeKeys>': body, sourceType

vite.config.ts:

/// <reference types="vitest" />
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import { reactScopedCssPlugin } from 'rollup-plugin-react-scoped-css';
import browserslistToEsbuild from 'browserslist-to-esbuild';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  // Load env file based on `mode` in the current working directory.
  // Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
  const env = loadEnv(mode, process.cwd());
  return {
    define: {
      __APP_ENV__: JSON.stringify(env.APP_ENV),
    },
    plugins: [
      laravel({
        input: 'resources/js/app.tsx',
        refresh: true,
      }),
      react(),
      viteTsconfigPaths(),
      reactScopedCssPlugin(),
    ],
    resolve: {
      alias: {
        '@': '/resources/js',
      },
    },
    server: {
      hmr: {
        host: 'localhost',
      },
      host: true,
      port: +env.VITE_PORT,
      strictPort: true,
      watch: { usePolling: true },
    },
    build: {
      manifest: true,
      rollupOptions: {
        external: ['fsevents'],
        output: {
          manualChunks: {
            react: ['react', 'react-dom'],
            mdb: ['mdb-react-ui-kit'],
            'react-datepicker': ['react-datepicker'],
            'react-big-calendar': ['react-big-calendar'],
            'react-datetime': ['react-datetime'],
          },
        },
      },
      target: browserslistToEsbuild(['>0.2%', 'not dead', 'not op_mini all']),
    },
    test: {
      environment: 'jsdom',
      setupFiles: './resources/js/setupTests.js',
    },
  };
});
cmseguin commented 3 months ago

Which version of the plugin and vite are you using, typically this happens when you use an old version of this plugin with vite 5 or version 1 of this plugin with vite 4

On Wed, Jun 12, 2024, 10:20 a.m. aae-gwhitehorn @.***> wrote:

When I add this to the plugins array, I get the following error from eslint on the export default line:

No overload matches this call. The last overload gave the following error. Argument of type '({ command, mode }: ConfigEnv) => { define: { APP_ENV: string; }; plugins: (PluginOption[] | Plugin | VitePartialPlugin[])[]; resolve: { alias: { ...; }; }; server: { ...; }; build: { ...; }; test: { ...; }; }' is not assignable to parameter of type 'UserConfigExport'. Type '({ command, mode }: ConfigEnv) => { define: { APP_ENV: string; }; plugins: (PluginOption[] | Plugin | VitePartialPlugin[])[]; resolve: { alias: { ...; }; }; server: { ...; }; build: { ...; }; test: { ...; }; }' is not assignable to type 'UserConfigFnObject'. Call signature return types '{ define: { __APP_ENV__: string; }; plugins: (PluginOption[] | Plugin | VitePartialPlugin[])[]; resolve: { alias: { '@': string; }; }; server: { hmr: { host: string; }; host: true; port: number; strictPort: true; watch: { ...; }; }; build: { ...; }; test: { ...; }; }' and 'UserConfig' are incompatible. The types of 'plugins' are incompatible between these types. Type '(PluginOption[] | Plugin | VitePartialPlugin[])[]' is not assignable to type 'PluginOption[]'. Type 'PluginOption[] | Plugin | VitePartialPlugin[]' is not assignable to type 'PluginOption'. Type 'VitePartialPlugin[]' is not assignable to type 'PluginOption'. Type 'VitePartialPlugin[]' is not assignable to type 'PluginOption[]'. Type 'VitePartialPlugin' is not assignable to type 'PluginOption'. Type 'VitePartialPlugin' is not assignable to type 'Plugin'. Types of property 'load' are incompatible. Type 'ObjectHook<(this: PluginContext, id: string) => LoadResult | Promise, {}>' is not assignable to type 'ObjectHook<(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise>'. Type '(this: PluginContext, id: string) => LoadResult | Promise' is not assignable to type 'ObjectHook<(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise>'. Type '(this: PluginContext, id: string) => LoadResult | Promise' is not assignable to type '(this: PluginContext, id: string, options?: { ssr?: boolean; }) => LoadResult | Promise'. Type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").LoadResult | Promise<import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").LoadResult>' is not assignable to type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").LoadResult | Promise<import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").LoadResult>'. Type 'SourceDescription' is not assignable to type 'LoadResult | Promise'. Type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/rollup/dist/rollup").SourceDescription' is not assignable to type 'import("/home/gwhitehorn/code/aae-intranet/node_modules/vite/node_modules/rollup/dist/rollup").SourceDescription'. Types of property 'ast' are incompatible. Type 'AstNode' is not assignable to type 'ProgramNode'. Type 'AstNode' is missing the following properties from type 'Omit<Program, OmittedEstreeKeys>': body, sourceType

vite.config.ts:

/// import { defineConfig, loadEnv } from 'vite';import laravel from 'laravel-vite-plugin';import react from @.***/plugin-react';import viteTsconfigPaths from 'vite-tsconfig-paths';import { reactScopedCssPlugin } from 'rollup-plugin-react-scoped-css';import browserslistToEsbuild from 'browserslist-to-esbuild'; // https://vitejs.dev/config/export default defineConfig(({ command, mode }) => { // Load env file based on mode in the current working directory. // Set the third parameter to '' to load all env regardless of the VITE_ prefix. const env = loadEnv(mode, process.cwd()); return { define: { __APP_ENV__: JSON.stringify(env.APP_ENV), }, plugins: [ laravel({ input: 'resources/js/app.tsx', refresh: true, }), react(), viteTsconfigPaths(), reactScopedCssPlugin(), ], resolve: { alias: { '@': '/resources/js', }, }, server: { hmr: { host: 'localhost', }, host: true, port: +env.VITE_PORT, strictPort: true, watch: { usePolling: true }, }, build: { manifest: true, rollupOptions: { external: ['fsevents'], output: { manualChunks: { react: ['react', 'react-dom'], mdb: ['mdb-react-ui-kit'], 'react-datepicker': ['react-datepicker'], 'react-big-calendar': ['react-big-calendar'], 'react-datetime': ['react-datetime'], }, }, }, target: browserslistToEsbuild(['>0.2%', 'not dead', 'not op_mini all']), }, test: { environment: 'jsdom', setupFiles: './resources/js/setupTests.js', }, };});

— Reply to this email directly, view it on GitHub https://github.com/cmseguin/rollup-plugin-react-scoped-css/issues/60, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEBOHIWRIM54UKSAMPYNWDZHB7OJAVCNFSM6AAAAABJGZJHFSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DSMZRGE4DQMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

aae-gwhitehorn commented 3 months ago

Version constraints: vite: ^5.2.11 rollup-plugin-react-scoped-css: ^1.0.0

cmseguin commented 3 months ago

If you delete your lock file and your node_modules folder, and re-install your dependecies, is the error going away?

On Wed, Jun 12, 2024, 11:33 a.m. aae-gwhitehorn @.***> wrote:

Version constraints: vite: ^5.2.11 rollup-plugin-react-scoped-css: ^1.0.0

— Reply to this email directly, view it on GitHub https://github.com/cmseguin/rollup-plugin-react-scoped-css/issues/60#issuecomment-2163669999, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEBOHJAFPADNYECVYOFFVDZHCH7ZAVCNFSM6AAAAABJGZJHFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRTGY3DSOJZHE . You are receiving this because you commented.Message ID: @.***>