PlayForm / Compress

🗜️ Compress —
https://NPMJS.Org/@playform/compress
MIT License
479 stars 12 forks source link

After upgrading to v0.0.4: Type 'AstroIntegration' is not assignable to type AstroIntegration #355

Closed azat-io closed 3 months ago

azat-io commented 3 months ago

Hi. I have a problem with types after upgrading the plugin to version 0.0.4.

"@playform/compress": "^0.0.4",
"astro": "^4.8.3",

Here is a part of astro.config.ts:

import compress from '@playform/compress'
import { defineConfig } from 'astro/config'

export default defineConfig({
  integrations: [
    compress({
      Exclude: [
        (file: string) => file.endsWith('.png') && !file.includes('hero.'),
      ],
      Image: process.env.COMPRESS_IMAGES !== 'false',
      JavaScript: true,
      HTML: true,
      SVG: true,
    }),
  ],
  // ...
})

I get the following error:

astro.config.ts:86:5 - error TS2322: Type 'AstroIntegration' is not assignable to type 'false | AstroIntegration | (false | AstroIntegration | null | undefined)[] | null | undefined'.
  Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration'.
    The types of 'hooks['astro:config:setup']' are incompatible between these types.
      Type '(options: { config: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+nod...' is not assignable to type '(options: { config: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+nod...'.
        Types of parameters 'options' and 'options' are incompatible.
          Type '{ config: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11...' is not assignable to type '{ config: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11...'.
            The types of 'config.integrations' are incompatible between these types.
              Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration[]' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration[]'.
                Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").AstroIntegration'.
                  The types of 'hooks['astro:build:ssr']' are incompatible between these types.
                    Type '(options: { manifest: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest; entryPoints: Map<...>; middlewareEntryPoint: URL | undefined; logger: import("/Users/azat/...' is not assignable to type '(options: { manifest: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest; entryPoints: Map<...>; middlewareEntryPoint: URL | undefined; logger: import("/Users/azat/...'.
                      Types of parameters 'options' and 'options' are incompatible.
                        Type '{ manifest: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest; entryPoints: Map<...>; middlewareEntryPoint: URL | undefined; logger: import("/Users/azat/Developer/...' is not assignable to type '{ manifest: import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest; entryPoints: Map<...>; middlewareEntryPoint: URL | undefined; logger: import("/Users/azat/Developer/...'.
                          Types of property 'manifest' are incompatible.
                            Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/core/app/types").SerializedSSRManifest' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                              Type 'SerializedSSRManifest' is not assignable to type 'Omit<SSRManifest, "assets" | "middleware" | "routes" | "componentMetadata" | "inlinedScripts" | "clientDirectives">' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                                The types returned by 'pageModule.page()' are incompatible between these types.
                                  Type 'Promise<import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").ComponentInstance>' is not assignable to type 'Promise<import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").ComponentInstance>'.
                                    Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").ComponentInstance' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/@types/astro").ComponentInstance' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                                      The types returned by 'default(...)' are incompatible between these types.
                                        Type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/runtime/server/render/astro/factory").AstroFactoryReturnValue | Promise<...>' is not assignable to type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/runtime/server/render/astro/factory").AstroFactoryReturnValue | Promise<...>'.
                                          Type 'RenderTemplateResult' is not assignable to type 'AstroFactoryReturnValue | Promise<AstroFactoryReturnValue>'.
                                            Property '[renderTemplateResultSym]' is missing in type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.1_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/runtime/server/render/astro/render-template").RenderTemplateResult' but required in type 'import("/Users/azat/Developer/azat-io/node_modules/.pnpm/astro@4.8.3_@types+node@20.12.11_lightningcss@1.24.1_terser@5.31.0_typescript@5.4.5/node_modules/astro/dist/runtime/server/render/astro/render-template").RenderTemplateResult'
kitschpatrol commented 3 months ago

Same here, possibly related: #330

NikolaRHristov commented 3 months ago

It stems from https://ptb.discord.com/channels/830184174198718474/1197638002764152843/1215607292792414228, somewhere in the dependency tree there are two different versions of astro being used.

NikolaRHristov commented 3 months ago

This is a potential fix for it - https://github.com/PlayForm/Compress/issues/329 since it will adjust the versions accordingly.

bennycode commented 3 months ago

I ran into this problem when upgrading from Astro 4.6.3 to 4.9.1.

Doing npm explain astro showed me that an older version of Astro is brought in by @playform/compress:

astro@"4.8.1" from @playform/compress@0.0.4

@NikolaRHristov I wonder if it comes from locking the astro peer dependency to a fix version?

https://github.com/PlayForm/Compress/blob/Current/package.json#L57

NikolaRHristov commented 3 months ago

@bennycode This is the new change it will be released shortly. The previous version had astro in the dependencies key this is why it was erroring. See https://github.com/PlayForm/Compress/issues/329#issuecomment-2126798109

NikolaRHristov commented 3 months ago

@bennycode @azat-io Should be fixed the latest astro-compress v2.2.24 and @playform/compress v0.0.6 Can you give it a go ?

bennycode commented 3 months ago

Sure! Happy to test. I tried to install it but it gives me this error:

npm i @playform/compress
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: @typescripttv/website@2.0.0
npm ERR! Found: @playform/document@0.0.6
npm ERR! node_modules/@playform/document
npm ERR!   peerOptional @playform/document@"0.0.6" from @playform/build@0.0.9
npm ERR!   node_modules/@playform/build
npm ERR!     peerOptional @playform/build@"0.0.9" from @playform/compress@0.0.6
npm ERR!     node_modules/@playform/compress
npm ERR!       @playform/compress@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @playform/document@"0.0.7" from @playform/compress@0.0.6
npm ERR! node_modules/@playform/compress
npm ERR!   @playform/compress@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
azat-io commented 3 months ago

Looks like problem was fixed in v0.0.6 👍 My package manager is pnpm.

NikolaRHristov commented 3 months ago

@bennycode Thank you ! I was able to reproduce. As a hotfix I can offer you to place an .npmrc file in the project root with the following contents:

legacy-peer-deps=true

I was using it with this big .npmrc file that always auto corrects these issues. Will look into it.

NikolaRHristov commented 3 months ago

@bennycode Should be fixed for you in the latest astro-compress v2.2.25 and @playform/compress v0.0.7

kitschpatrol commented 3 months ago

The type errors are now fixed on my end, thank you.

azat-io commented 3 months ago

The same problem after updating Astro to v4.10.0. Can you reopen the issue?

kitschpatrol commented 3 months ago

Oy, yeah this popped back up for me as well in Astro 4.10.0.

NikolaRHristov commented 3 months ago

There's a pull tracking this for anyone following https://github.com/PlayForm/Compress/pull/370/files

NikolaRHristov commented 3 months ago

Should be fixed in the latest astro-compress v2.2.27 and @playform/compress v0.0.12

kitschpatrol commented 3 months ago

Fixed again in v0.0.12 for me, thank you!