withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
44.08k stars 2.29k forks source link

@astrojs/upgrade does not update sharp #9268

Open hfournier opened 7 months ago

hfournier commented 7 months ago

Astro Info

Astro                    v3.6.4
Node                     v18.17.1
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Ran npm outdated and got:

Package  Current  Wanted  Latest  Location            Depended by
astro      3.6.3   3.6.4   3.6.4  node_modules/astro  astro-test
sharp     0.32.6  0.32.6  0.33.0  node_modules/sharp  astro-test

ran npx @astrojs/upgrade:

 astro   Integration upgrade in progress.

      ◼  @astrojs/mdx is up to date on v1.1.5
      ◼  @astrojs/rss is up to date on v3.0.0
      ◼  @astrojs/tailwind is up to date on v5.0.2
      ●  astro will be updated to v3.6.4

      ✔  Installed dependencies!

reran npm outdated:

Package  Current  Wanted  Latest  Location            Depended by
sharp     0.32.6  0.32.6  0.33.0  node_modules/sharp  astro-test

What's the expected result?

Expected the sharp dependency to be updated.

Link to Minimal Reproducible Example

n/a

Participation

jacobdalamb commented 7 months ago

I believe this is intentional behavior. @astrojs/upgrade focuses on Astro integrations and does not manage other npm dependencies.

hfournier commented 7 months ago

The description in the read.me is: "A command-line tool for upgrading your Astro integrations and dependencies." I believe sharp is used by the <Image /> component to optimize images. Or, do we no longer have to add it as a dependency in our projects? Is Astro including it as its own dependency?

hfournier commented 7 months ago

According docs, it looks like you may only need to install it if you're using pnpm. But, if that is the case, shouldn't it get upgraded along with the rest?

rishi-raj-jain commented 7 months ago

I think that's because it's marked as optionalDep. https://github.com/withastro/astro/blob/main/packages/astro/package.json#L178

rishi-raj-jain commented 7 months ago

But did sharp upgrade between Astro version releases? Then only I think it makes sense to expect an automatic upgrade? Checking that.

rishi-raj-jain commented 7 months ago

Yeah, I do not see any changes between v3.6.4 to 4 (I checked it manually between commits, pardon if I missed any).

lilnasy commented 7 months ago

I would expect it to only handle first party integrations, going by how it's described in the PR.

I'll let @natemoo-re confirm whether the docs need to be slightly adjusted around "dependencies".

Boston343 commented 7 months ago

Might make a separate issue on this, but upgrading sharp to 0.33.0 breaks builds for me in both Astro 3.6.4 and 4.0.2. Dev mode still works fine but when building locally I get:

MissingSharp: Could not find Sharp. Please install Sharp (`sharp`) manually into your project or migrate to another image service.
    at loadSharp (file:///.../dist/chunks/astro/assets-service_x_nToqfa.mjs:352:11)
    at async Object.transform (file:///.../dist/chunks/astro/assets-service_x_nToqfa.mjs:364:15)
    at async generateImageInternal (file:///.../node_modules/astro/dist/assets/build/generate.js:119:24)
    at async generateImage (file:///.../node_modules/astro/dist/assets/build/generate.js:66:28)
    at async file:///.../node_modules/p-queue/dist/index.js:118:36 {
  loc: undefined,
  title: 'Could not find Sharp.',
  hint: "See Sharp's installation instructions for more information: https://sharp.pixelplumbing.com/install. If you are not relying on `astro:assets` to optimize, transform, or process any images, you can configure a passthrough image service instead of installing Sharp. See https://docs.astro.build/en/reference/errors/missing-sharp for more information.\n" +
    '\n' +
    'See https://docs.astro.build/en/guides/images/#default-image-service for more information on how to migrate to another image service.',
  frame: undefined,
  type: 'AstroError'
}

So, it's probably good it doesn't update this dependency automatically!

natemoo-re commented 7 months ago

Thanks for opening an issue! @astrojs/upgrade currently only handles a subset of dependencies: the astro package and any @astrojs/* packages. I do think we should handle peerDependencies of those packages as well, but we're currently not.

As a side note: if anyone is looking for a more general dependency management tool, I've heard good things about taze.

jcf commented 3 months ago

Might make a separate issue on this, but upgrading sharp to 0.33.0 breaks builds for me in both Astro 3.6.4 and 4.0.2. Dev mode still works fine but when building locally I get:

MissingSharp: Could not find Sharp. Please install Sharp (`sharp`) manually into your project or migrate to another image service.
    at loadSharp (file:///.../dist/chunks/astro/assets-service_x_nToqfa.mjs:352:11)
    at async Object.transform (file:///.../dist/chunks/astro/assets-service_x_nToqfa.mjs:364:15)
    at async generateImageInternal (file:///.../node_modules/astro/dist/assets/build/generate.js:119:24)
    at async generateImage (file:///.../node_modules/astro/dist/assets/build/generate.js:66:28)
    at async file:///.../node_modules/p-queue/dist/index.js:118:36 {
  loc: undefined,
  title: 'Could not find Sharp.',
  hint: "See Sharp's installation instructions for more information: https://sharp.pixelplumbing.com/install. If you are not relying on `astro:assets` to optimize, transform, or process any images, you can configure a passthrough image service instead of installing Sharp. See https://docs.astro.build/en/reference/errors/missing-sharp for more information.\n" +
    '\n' +
    'See https://docs.astro.build/en/guides/images/#default-image-service for more information on how to migrate to another image service.',
  frame: undefined,
  type: 'AstroError'
}

So, it's probably good it doesn't update this dependency automatically!

@Boston343 it's worth double-checking Sharp is compiling (npm rebuild --version sharp) in case you have an incompatible version of libtool floating around.

Boston343 commented 3 months ago

Oh man this was from a while ago! I appreciate the comment, but I've got it working at this point. I did have issues with astro-compress and astro wanting to use different versions of sharp (on linux) so I added this to my package.json file and it works for me.

I use it in my website templates too and no one has complained about it (aside from one person who was running an old npm version that needed updated). So it seems to be working now

  "overrides": {
    "sharp": "^0.33.0"
  }
nathanchere commented 1 month ago

This seems to be a frequently recurring issue. I've only managed to get it working again with downgrading sharp to 0.32 but that was a red herring. npm rebuild --version sharp and the typically recommended pnpm meddling didn't work. What did work was deleting package-lock.json (or bun.lockb or whatever), deleting sharp entirely from package.json, and then fresh npm/bun/whatever install.

When sharp is added to packages, there's some dependency drama going on and it says it can't find sharp. Remove the explicit sharp reference entirely and the problem appears to go away.