Skip to content

have_npm() / run_npm_install() never find npm on Windows (subprocess cannot resolve npm.cmd) #124

Open

Description

@denis124056-droid

Summary

On Windows, readabilipy.utils.have_npm() always returns False even when Node.js and npm are installed and on PATH, so the Readability.js extraction path is unreachable on Windows and the pure-Python fallback is always used.

Environment

  • Windows 11 (build 26300), Python 3.13.14
  • readabilipy 0.3.0
  • Node.js and npm 11.17.0 installed and on PATH; node.exe, npm.cmd and npm.ps1 all present in the Node.js directory; npm --version works from the same shell that spawned Python

Analysis

readabilipy/utils.py:

def have_npm():
    try:
        cp = subprocess.run(
            ["npm", "version"],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            check=True
        )
    except FileNotFoundError:
        return False
    return cp.returncode == 0

On Windows npm ships as npm.cmd / npm.ps1, not npm.exe. subprocess.run(["npm", ...]) does not resolve those shims, so it raises FileNotFoundError, have_npm() returns False, and every extraction prints:

Warning: A working NPM installation was not found. The package will use Python-based article extraction.
Warning: node executable not found, reverting to pure-Python mode. Install Node.js v10 or newer to use Readability.js.

The same resolution problem applies to subprocess.run(["npm", "install"], ...) in run_npm_install().

Suggested fix

Resolve the executable first with shutil.which("npm") - it returns the npm.cmd path on Windows and the plain npm path elsewhere - and invoke the resolved path in both have_npm() and run_npm_install().

Impact

Every Windows user silently gets the pure-Python extractor. In particular, mcp-server-fetch (modelcontextprotocol/servers) documents that installing Node.js makes it "use a different HTML simplifier that is more robust" - on Windows that never actually happens.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions