ITADN

Gitea npm registry rejects valid package metadata when repository or bin use string form

#38235Openblakelaperriere 创建于 2026-06-27
type/bug
B
blakelaperrierecommented
### Gitea Version 1.26.4 ### What happened? Sometimes Gitea rejects npm packages when publishing. It appears that this happens with packages that contain a string `bin` or `repository` in their `package.json`. I dug into Gitea's source, and it appears the issue is due to the structs in `modules/packages/npm/creator.go` modeling these fields too strictly: - `bin` is modeled as `map[string]string` though it's valid for this to be a string - https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin - `repository` is modeled as: ``` type Repository struct { -- Type string `json:"type"` URL string `json:"url"` Directory string `json:"directory,omitempty"` } ``` As with `bin`, `repository` can also be supplied as a string - https://docs.npmjs.com/cli/v11/configuring-npm/package-json#repository I also noticed that `bundledDependencies` is modeled as `[]string`, while technically npm specifies it can also be a boolean. Not very common, but worth mentioning. https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bundledependencies **To replicate** (prettier is a good example of a package with `bin` and `repository` both strings in its `package.json`): 1. `npm pack prettier` 2. `pnpm config set registry=https://git.example.com/api/packages/myorg/npm` 3. `pnpm publish --no-git-checks prettier-*.tgz` It hangs for a number of seconds, then returns: ``` 📦 prettier@3.8.5 → https://git.example.com/api/packages/myorg/npm/ [E500] 500 Internal Server Error - PUT https://git.example.com/api/packages/myorg/npm/prettier - json: cannot unmarshal JSON string into Go map[string]string within "/versions/3.8.5/bin" ``` And server logs: ``` 2026/06/27 02:29:59 HTTPRequest [I] router: completed PUT /api/packages/myorg/npm/prettier for 192.168.50.178:0, 500 Internal Server Error in 55.0ms @ npm/npm.go:156(npm.UploadPackage) 2026/06/27 02:29:59 .../api/packages/npm/npm.go:162:UploadPackage() [E] Package registry API internal error: 500 json: cannot unmarshal JSON string into Go map[string]string within "/versions/3.8.5/bin" ``` ### How are you running Gitea? Docker
0 条评论