Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error installing npm package with optionalDependencies #20771

Closed
oscarotero opened this issue Oct 3, 2023 · 2 comments · Fixed by #20772
Closed

Error installing npm package with optionalDependencies #20771

oscarotero opened this issue Oct 3, 2023 · 2 comments · Fixed by #20772
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@oscarotero
Copy link

I'm getting a very rare error installing npm:pagefind@1.0.4-beta.0

In v1.0.3 everything works fine. The package has some optionalDependencies with the binary file per os/platform. The package.json is:

{
  "name": "pagefind",
  "version": "1.0.3",
  "type": "module",
  "description": "Implement search on any static website.",
  "bin": "lib/runner/bin.cjs",
  "main": "lib/index.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/CloudCannon/pagefind"
  },
  "exports": {
    ".": {
      "types": "./types/index.d.ts",
      "import": "./lib/index.js"
    }
  },
  "types": "types/index.d.ts",
  "author": "CloudCannon",
  "license": "MIT",
  "optionalDependencies": {
    "@pagefind/linux-x64": "1.0.3",
    "@pagefind/linux-arm64": "1.0.3",
    "@pagefind/darwin-x64": "1.0.3",
    "@pagefind/darwin-arm64": "1.0.3",
    "@pagefind/windows-x64": "1.0.3"
  },
  "keywords": [
    "CloudCannon",
    "Cloud",
    "Cannon",
    "jamstack",
    "static",
    "search",
    "pagefind",
    "page",
    "find"
  ],
  "bugs": {
    "url": "https://github.com/CloudCannon/pagefind/issues"
  },
  "homepage": "https://github.com/CloudCannon/pagefind#readme",
  "devDependencies": {
    "@types/node": "^20.4.5"
  }
}

In v1.0.4 (both -rc0 and -beta.0), the optional dependencies are not installed, but the package.json is almost the same (except the versions of the dependencies):

{
  "name": "pagefind",
  "version": "1.0.4-beta.0",
  "type": "module",
  "description": "Implement search on any static website.",
  "bin": "lib/runner/bin.cjs",
  "main": "lib/index.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/CloudCannon/pagefind"
  },
  "exports": {
    ".": {
      "types": "./types/index.d.ts",
      "import": "./lib/index.js"
    }
  },
  "types": "types/index.d.ts",
  "author": "CloudCannon",
  "license": "MIT",
  "optionalDependencies": {
    "@pagefind/linux-x64": "1.0.4-beta.0",
    "@pagefind/linux-arm64": "1.0.4-beta.0",
    "@pagefind/darwin-x64": "1.0.4-beta.0",
    "@pagefind/darwin-arm64": "1.0.4-beta.0",
    "@pagefind/windows-x64": "1.0.4-beta.0"
  },
  "keywords": [
    "CloudCannon",
    "Cloud",
    "Cannon",
    "jamstack",
    "static",
    "search",
    "pagefind",
    "page",
    "find"
  ],
  "bugs": {
    "url": "https://github.com/CloudCannon/pagefind/issues"
  },
  "homepage": "https://github.com/CloudCannon/pagefind#readme",
  "devDependencies": {
    "@types/node": "^20.4.5"
  }
}

Diging into the registry.json file in the Deno's cache, I found that the 1.0.3 is resolved differently as 1.0.4-beta.0. In 1.0.3, the optionalDependencies are added also to the dependencies key:

"1.0.3": {
  "version": "1.0.3",
  "dist": {
    "tarball": "https://registry.npmjs.org/pagefind/-/pagefind-1.0.3.tgz",
    "shasum": "1ce2118408d42fbd303e8b567ed3fff134895138",
    "integrity": "sha512-ws7kmMxW6OuxzsOjj3YAx6TYq/54MiE3wfyBM3J5CInbZyBBvM2Z8c8IYvnMkBcb5v2EoB9DewXEekOEiDRu5g=="
  },
  "bin": {
    "pagefind": "lib/runner/bin.cjs"
  },
  "dependencies": {
    "@pagefind/linux-x64": "1.0.3",
    "@pagefind/darwin-x64": "1.0.3",
    "@pagefind/darwin-arm64": "1.0.3",
    "@pagefind/windows-x64": "1.0.3",
    "@pagefind/linux-arm64": "1.0.3"
  },
  "optionalDependencies": {
    "@pagefind/linux-x64": "1.0.3",
    "@pagefind/darwin-arm64": "1.0.3",
    "@pagefind/linux-arm64": "1.0.3",
    "@pagefind/darwin-x64": "1.0.3",
    "@pagefind/windows-x64": "1.0.3"
  },
  "peerDependencies": {},
  "peerDependenciesMeta": {},
  "os": [],
  "cpu": []
},

But the entry for 1.0.4-beta.0, the dependencies key is empty:

"1.0.4-beta.0": {
  "version": "1.0.4-beta.0",
  "dist": {
    "tarball": "https://registry.npmjs.org/pagefind/-/pagefind-1.0.4-beta.0.tgz",
    "shasum": "652b11b80626d8cb4ab7b6a5e40ea8bd1d838593",
    "integrity": "sha512-pFBKDXMpm6FXSEFa0GFB+OJjDC23163sOfLq87iWKCo9muXFeTvuRTGWeLAFTHQRKcL845+sFM5RJdSeZqd10Q=="
  },
  "bin": {
    "pagefind": "lib/runner/bin.cjs"
  },
  "dependencies": {},
  "optionalDependencies": {
    "@pagefind/linux-x64": "1.0.4-beta.0",
    "@pagefind/darwin-x64": "1.0.4-beta.0",
    "@pagefind/windows-x64": "1.0.4-beta.0",
    "@pagefind/darwin-arm64": "1.0.4-beta.0",
    "@pagefind/linux-arm64": "1.0.4-beta.0"
  },
  "peerDependencies": {},
  "peerDependenciesMeta": {},
  "os": [],
  "cpu": []
},

It looks like, for some reason, Deno is not considering these optional dependencies to be os/platform specific dependencies in 1.0.4.

I also found that if the binaries for 1.0.3 are already cached, Deno will use these files instead of the version specified in the package.json (1.0.4-beta.0).

cc @bglw

@dsherret dsherret added bug Something isn't working correctly node compat labels Oct 3, 2023
@dsherret dsherret self-assigned this Oct 3, 2023
dsherret added a commit that referenced this issue Oct 3, 2023
* fix: handle optional deps not found in dependencies map
(denoland/deno_npm#38)
* fix: resolve a version requirement to the latest dist tag if it
matches (denoland/deno_npm#37)

Closes #20771
@prabhu
Copy link

prabhu commented Oct 7, 2023

Could someone explain the fix? Would deno install the correct platform and architecture specific optional dependencies during deno install and deno run? Is it possible to expose command line arguments such as --only or --with to further customize the behaviour?

@dsherret
Copy link
Member

dsherret commented Oct 7, 2023

@prabhu Deno was previously relying on the fact that the optionalDependencies and dependencies almost always matched in npm's api. It already had optional dependency support.

Is it possible to expose command line arguments such as --only or --with to further customize the behaviour?

In a few months you'll be able to use npm install/pnpm install/etc. with Deno and this should cover that use case.

bartlomieju pushed a commit that referenced this issue Oct 12, 2023
* fix: handle optional deps not found in dependencies map
(denoland/deno_npm#38)
* fix: resolve a version requirement to the latest dist tag if it
matches (denoland/deno_npm#37)

Closes #20771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants