PlayForm / Compress

πŸ—œοΈβ€Compress —
https://playform.github.io/Compress/
Other
504 stars 12 forks source link

vercel: Error while building #244

Closed SyedMuzamilM closed 10 months ago

SyedMuzamilM commented 10 months ago
[vite] Error when evaluating SSR module /opt/buildhome/repo/astro.config.mjs: failed to import "astro-compress"
11:18:19.066    |- Error: Could not load the "sharp" module using the linux-x64 runtime
11:18:19.067    Possible solutions:
11:18:19.067    - Add platform-specific dependencies:
11:18:19.067        npm install --os=linux --cpu=x64 sharp
11:18:19.068      or
11:18:19.068        npm install --force @img/sharp-linux-x64
11:18:19.068    - Consult the installation documentation: https://sharp.pixelplumbing.com/install
11:18:19.068        at Object.<anonymous> (/opt/buildhome/repo/node_modules/sharp/lib/sharp.js:85:9)
11:18:19.068        at Module._compile (node:internal/modules/cjs/loader:1233:14)
11:18:19.068        at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
11:18:19.068        at Module.load (node:internal/modules/cjs/loader:1091:32)
11:18:19.069        at Module._load (node:internal/modules/cjs/loader:938:12)
11:18:19.069        at Module.require (node:internal/modules/cjs/loader:1115:19)
11:18:19.069        at require (node:internal/modules/helpers:119:18)
11:18:19.069        at Object.<anonymous> (/opt/buildhome/repo/node_modules/sharp/lib/constructor.js:10:1)
11:18:19.069        at Module._compile (node:internal/modules/cjs/loader:1233:14)
11:18:19.069        at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
11:18:19.069    
11:18:19.069    [astro] Unable to load your Astro config
11:18:19.069    
11:18:19.538    Could not load the "sharp" module using the linux-x64 runtime
11:18:19.539
NikolaRHristov commented 10 months ago

Hi, @SyedMuzamilM, can you provide more information on your environment, the OS, hosting provider, stuff like that, so that we can investigate it further?

In the meantime, you can try running the #no-sharp branch, which disables image compression, but removes this error. To install it just replace the package.json entry for astro-compress with:

{
    "astro-compress": "astro-community/AstroCompress#no-sharp"
}

or:

npm install -D -E astro-community/AstroCompress#no-sharp
SyedMuzamilM commented 10 months ago

OS is windows 10 and I deployed it to Cloudflare Pages and Vercel both gave the same error.

Will try this command and see if it works.

NikolaRHristov commented 10 months ago

Which Node version are you using?

NikolaRHristov commented 10 months ago

There are similar issues in the sharp repository. Maybe try npm ls sharp as per https://github.com/lovell/sharp/issues/3896#issuecomment-1857516925 and see if there's a version mismatch somewhere in your code or with an outdated dependency.

SyedMuzamilM commented 10 months ago

Which Node version are you using?

I am using the latest node version 20.10.0

SyedMuzamilM commented 10 months ago

There are similar issues in the sharp repository. Maybe try npm ls sharp as per https://github.com/lovell/sharp/issues/3896#issuecomment-1857516925 and see if there's a version mismatch somewhere in your code or with an outdated dependency.

Will check the and see if this works.

The previous command worked fine which doesn't use sharp. It is now getting deployed properly.

Will check if any other dependency is using sharp so that the error could be resolved.

J05HI commented 10 months ago

Hey @NikolaRHristov I've the same error on my M1 MBA. I'm on Node v20.10.0.

Installing astro compress:

> joshua@MacBook-Air-von-Joshua x-website % yarn add astro-compress --save-dev
yarn add v1.22.19
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
warning sharp@0.33.0: The engine "libvips" appears to be invalid.
warning @img/sharp-libvips-darwin-arm64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-darwin-arm64@1.0.0: The engine "macos" appears to be invalid.
warning @img/sharp-darwin-arm64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-darwin-arm64@0.33.0: The engine "glibc" appears to be invalid.
warning @img/sharp-darwin-x64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-darwin-x64@0.33.0: The engine "glibc" appears to be invalid.
warning @img/sharp-libvips-darwin-x64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-darwin-x64@1.0.0: The engine "macos" appears to be invalid.
warning @img/sharp-libvips-linux-arm@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linux-arm@1.0.0: The engine "glibc" appears to be invalid.
warning @img/sharp-libvips-linux-arm64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linux-arm64@1.0.0: The engine "glibc" appears to be invalid.
warning @img/sharp-libvips-linuxmusl-arm64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linuxmusl-arm64@1.0.0: The engine "musl" appears to be invalid.
warning @img/sharp-libvips-linux-x64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linux-x64@1.0.0: The engine "glibc" appears to be invalid.
warning @img/sharp-libvips-linuxmusl-x64@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linuxmusl-x64@1.0.0: The engine "musl" appears to be invalid.
warning @img/sharp-libvips-linux-s390x@1.0.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-libvips-linux-s390x@1.0.0: The engine "glibc" appears to be invalid.
warning @img/sharp-linux-arm@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linux-arm@0.33.0: The engine "glibc" appears to be invalid.
warning @img/sharp-linux-s390x@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linux-s390x@0.33.0: The engine "glibc" appears to be invalid.
warning @img/sharp-win32-ia32@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-wasm32@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linuxmusl-x64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linuxmusl-x64@0.33.0: The engine "musl" appears to be invalid.
warning @img/sharp-win32-x64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linux-arm64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linux-arm64@0.33.0: The engine "glibc" appears to be invalid.
warning @img/sharp-linuxmusl-arm64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linuxmusl-arm64@0.33.0: The engine "musl" appears to be invalid.
warning @img/sharp-linux-x64@0.33.0: The engine "pnpm" appears to be invalid.
warning @img/sharp-linux-x64@0.33.0: The engine "glibc" appears to be invalid.
[3/4] πŸ”—  Linking dependencies...
warning " > postcss-css-variables@0.19.0" has unmet peer dependency "postcss@^8.2.6".
warning " > postcss-variable-compress@3.0.0" has unmet peer dependency "postcss@^8.2.8".
[4/4] πŸ”¨  Building fresh packages...
success Saved lockfile.
success Saved 42 new dependencies.
info Direct dependencies
└─ astro-compress@2.2.5
info All dependencies
β”œβ”€ @jridgewell/source-map@0.3.5
β”œβ”€ @types/css-tree@2.3.4
β”œβ”€ @types/csso@5.0.3
β”œβ”€ @types/html-minifier-terser@7.0.2
β”œβ”€ ansi-sequence-parser@1.1.1
β”œβ”€ array-union@2.1.0
β”œβ”€ astro-compress@2.2.5
β”œβ”€ buffer-from@1.1.2
β”œβ”€ camel-case@4.1.2
β”œβ”€ clean-css@5.3.3
β”œβ”€ dir-glob@3.0.1
β”œβ”€ dot-case@3.0.4
β”œβ”€ fs-extra@10.1.0
β”œβ”€ globby@11.1.0
β”œβ”€ html-minifier-terser@7.2.0
β”œβ”€ ignore@5.3.0
β”œβ”€ jsonc-parser@3.2.0
β”œβ”€ jsonfile@6.1.0
β”œβ”€ lower-case@2.0.2
β”œβ”€ lunr@2.3.9
β”œβ”€ marked@4.3.0
β”œβ”€ param-case@3.0.4
β”œβ”€ pascal-case@3.1.2
β”œβ”€ path-type@4.0.0
β”œβ”€ relateurl@0.2.7
β”œβ”€ sharp@0.33.0
β”œβ”€ shiki@0.14.7
β”œβ”€ slash@3.0.0
β”œβ”€ source-map-support@0.5.21
β”œβ”€ svgo@3.1.0
β”œβ”€ terser@5.26.0
β”œβ”€ typedoc-plugin-keywords@1.6.0
β”œβ”€ typedoc-plugin-mdn-links@3.1.7
β”œβ”€ typedoc-plugin-merge-modules@5.1.0
β”œβ”€ typedoc-plugin-remove-references@0.0.6
β”œβ”€ typedoc-plugin-rename-defaults@0.7.0
β”œβ”€ typedoc-plugin-zod@1.1.0
β”œβ”€ typedoc@0.25.4
β”œβ”€ typescript-esbuild@0.3.3
β”œβ”€ typescript@5.3.3
β”œβ”€ vscode-oniguruma@1.7.0
└─ vscode-textmate@8.0.0
✨  Done in 13.56s.

Running ls sharp:

> joshua@MacBook-Air-von-Joshua x-website % npm ls sharp                      
x-website@0.0.1 /Users/joshua/DEV/x-website
β”œβ”€β”¬ astro-compress@2.2.5
 β”‚    └── sharp@0.33.0
└─┬ astro@3.6.4
       └── sharp@0.32.6

My dependencies:

  "devDependencies": {
    "@astrojs/sitemap": "^3.0.3",
    "@astrojs/tailwind": "^5.0.2",
    "@storyblok/astro": "^3.0.1",
    "@vitejs/plugin-basic-ssl": "^1.0.2",
    "astro": "^3.6.4",
    "astro-critters": "^2.0.11",
    "astro-compress": "^2.2.5",
    "astro-purgecss": "^3.2.1",
    "astro-rename": "^1.1.2",
    "lightningcss": "^1.22.1",
    "postcss-css-variables": "^0.19.0",
    "postcss-variable-compress": "^3.0.0",
    "prettier": "^3.1.0",
    "prettier-plugin-astro": "^0.12.2",
    "prettier-plugin-tailwindcss": "^0.5.7",
    "purgecss": "^5.0.0",
    "tailwindcss": "^3.3.6",
    "vite": "^5.0.5"
  },
  "dependencies": {
    "@astrojs/prefetch": "^0.4.1",
    "@fontsource-variable/inter": "^5.0.15",
    "astro-icon": "^0.8.1"
  }
NikolaRHristov commented 10 months ago

I see, astro 3.6.4 is running an older version of sharp than astro-compress

npm ls sharp
β”œβ”€β”¬ astro-compress@2.2.5
β”‚ └── sharp@0.33.0
└─┬ astro@3.6.4
└── sharp@0.32.6

Can you try pinning the version of sharp for astro with the same one astro-compress uses? This is done by updating the package.json to override the dependency like so:

package.json

{
  "name": "your-project",
  "version": "1.0.0",
  "dependencies": {
    "astro": "3.6.4",
    "astro-compress": "2.2.5"
  },
  "resolutions": {
    "sharp": "0.33.0"
  }
}

or

package.json

{
  "overrides": {
    "astro": {
      "sharp": "0.33.0"
    }
  }
}

Update: resolutions works only on Yarn. Use the overrides method.

SyedMuzamilM commented 10 months ago

Since astro:image uses sharp as its default image service, I think that might be causing issues when using astro-compress

Astro Default Image Service you can check it here.

J05HI commented 10 months ago

@NikolaRHristov Forcing it to v0.33.0 works perfectly fine. Thank you!

jpkhawam commented 9 months ago

Can you try pinning the version of sharp for astro with the same one astro-compress uses? This is done by updating the package.json to override the dependency like so:

package.json

  "resolutions": {
    "sharp": "0.33.0"
  }

This fixed it for me! Thank you for your work

kswedberg commented 9 months ago

Interesting… setting "resolutions": {"sharp": "0.32.6"} worked with my M1 MacBook Air, but setting it to 0.33.0 resulted in the error:

[vite] Error when evaluating SSR module /Users/kswedberg/Sites/ks/blog.karlswedberg.com/astro.config.mjs: failed to import "astro-compress"
|- Error: Could not load the "sharp" module using the darwin-arm64 runtime
NikolaRHristov commented 9 months ago

Interesting… setting "resolutions": {"sharp": "0.32.6"} worked with my M1 MacBook Air, but setting it to 0.33.0 resulted in the error:

[vite] Error when evaluating SSR module /Users/kswedberg/Sites/ks/blog.karlswedberg.com/astro.config.mjs: failed to import "astro-compress"
|- Error: Could not load the "sharp" module using the darwin-arm64 runtime

Use:

{
  "overrides": {
    "astro": {
      "sharp": "0.33.0"
    }
  }
}

resolutions is supported only on Yarn.

kswedberg commented 9 months ago

@NikolaRHristov , I'm using Yarn. Thanks for the suggestion, but neither resolutions nor overrides worked with sharp 0.33.0. Maybe I need to leave it set as "resolutions": {"sharp": "0.32.6"} β€” unless you have another idea I can try.

NikolaRHristov commented 9 months ago

@NikolaRHristov , I'm using Yarn. Thanks for the suggestion, but neither resolutions nor overrides worked with sharp 0.33.0. Maybe I need to leave it set as "resolutions": {"sharp": "0.32.6"} β€” unless you have another idea I can try.

Well, the version of sharp depends on the AstroCompress and Astro versions and whichever you choose to override. I'm just suggesting overrides as a general solution since resolutions is only supported on Yarn.

NikolaRHristov commented 9 months ago

I'll see if I can implement something dynamic that overrides the AstroCompress sharp version pre-install to match Astro's sharp version.

kswedberg commented 9 months ago

Well, the version of sharp depends on the AstroCompress and Astro versions and whichever you choose to override

Yeah, I get that. All I'm saying is that astro build fails with the error when I "choose to override" using 0.33.0, while it works with 0.32.6. In case it helps at all, I'm using astro 3.4.0 and astro-compress 2.2.5. And here is the (truncated) stdout of yarn why sharp:

=> Found "sharp@0.33.0"
info Reasons this module exists
   - "astro-compress" depends on it
   - Hoisted from "astro-compress#sharp"

=> Found "astro#sharp@0.32.6"
info This module exists because "astro" depends on it.

I'll see if I can implement something dynamic that overrides the AstroCompress sharp version pre-install to match Astro's sharp version.

That would be wonderful. Thanks so much!

NikolaRHristov commented 9 months ago
{
  "overrides": {
    "astro-compress": {
      "sharp": "0.32.6"
    }
  }
}

Does this work?

kswedberg commented 9 months ago

No, "overrides": {"astro-compress": {"sharp": "0.32.6"}} didn't work for me. I'll just keep using "resolutions": {"sharp": "0.32.6"} until some later version irons out the issues. thanks again

NikolaRHristov commented 9 months ago

No, "overrides": {"astro-compress": {"sharp": "0.32.6"}} didn't work for me. I'll just keep using "resolutions": {"sharp": "0.32.6"} until some later version irons out the issues. thanks again

@kswedberg I'm sorry, can I use you to debug something else? Does the resolutions method work for sharp 0.33.1 with the latest AstroCompress and Astro?

kswedberg commented 9 months ago

No problem, happy to help. Trying it with "resolutions": {"sharp": "0.33.1"} did not work, unfortunately. astro build produced this:

12:29:08 PM [vite] Error when evaluating SSR module /Users/kswedberg/Sites/ks/blog.karlswedberg.com/astro.config.mjs: failed to import "astro-compress"
|- Error: Could not load the "sharp" module using the darwin-arm64 runtime
Possible solutions:

... [a bunch of stuff] ...

[astro] Unable to load your Astro config
 error   Could not load the "sharp" module using the darwin-arm64 runtime
NikolaRHristov commented 9 months ago

Thank you so much! We will investigate this further, for now glad that the resolutions hotfix works with sharp 0.32.6 and both Astro and AstroCompress installed.