Skip to content

Enhancement: support building from source with npm v12+ #4458

Closed

Description

@lovell

This issue only affects those building sharp from source, which include those using a globally-installed libvips.

There are some upstream changes to npm v11 relating to "unknown" flags, will move from warning to error in npm v12 - see npm/cli#8153

Those affected by this may have seen the following warning:

npm warn Unknown cli config "--build-from-source". This will stop working in the next major version of npm.

At the moment the scenarios that result in sharp being built from source:

  • a globally-installed libvips is detected
  • the npm install --build-from-source flag is used

...plus there is some control over these via the SHARP_IGNORE_GLOBAL_LIBVIPS and SHARP_FORCE_GLOBAL_LIBVIPS environment variables.

The upstream advice seems to be the use of an environment variable prefixed with npm_package_config_, and we can use this opportunity to consolidate all the above logic into a single environment variable, something like npm_package_config_sharp_global_libvips.

This might behave a bit like Meson's tri-state features option, however I'm not a fan of the disabled/enabled wording, so this needs a little more thought, perhaps allowing values such as force, ignore and auto.

Activity

  1. lovell commented on Oct 3, 2025

    @lovell
    OwnerAuthor

    Having now investigated this, a much simpler solution is to move the generic install script to a dedicated "I know I want to build sharp from source" script instead, which could be run using something like:

    // PROPOSAL, NOT YET IMPLEMENTED
    npm install package-that-depends-on-sharp
    npm explore sharp -- npm run build

    This approach would still respect existing environment variables, but would remove deprecate support for the --build-from-source flag.

  2. added this to the v0.34.5 milestone on Oct 7, 2025
  3. changed the title [-]Possible breaking change for those building from source with npm v12[/-] [+]Enhancement: support building from source with npm v12+[/+] on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions