无法发布我的 npm 包出现此错误 415 不支持的媒体类型 - 在 tarball 中找不到 package.json?

unable to publish my npm package got this error 415 Unsupported Media Type - No package.json found in tarball?

当我 运行 npm publish 它显示 415 Unsupported Media Type - PUT https://registry.npmjs.org/json-to-plain-text - 在 tarball

中找不到 package.json

不知道为什么会这样,是不是我的电脑有问题。我正在使用鹦鹉 OS 和 nodejs 版本 v12.22.5 和 npm 版本 7.5.2

~$ cat  /home/sumith/.npm/_logs/2022-03-21T16_14_00_789Z-debug.log

0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'publish' ]
1 info using npm@7.5.2
2 info using node@v12.22.5
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/home/sumith/repos/json-to-plain-text/.npmrc Completed in 0ms
9 timing config:load:project Completed in 0ms
10 timing config:load:file:/home/sumith/.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 7ms
19 verbose npm-session 7f303ef810561d7f
20 timing npm:load Completed in 14ms
21 verbose publish [ '.' ]
22 notice
23 notice   json-to-plain-text@1.0.3
24 notice === Tarball Contents ===
25 notice 11B   /.gitattributes
25 notice 4B    /.prettierignore
25 notice 96B   /.prettierrc.json
25 notice 3.7kB /index.js
25 notice 7B    /json-to-plain-text.version
25 notice 1.5kB /lib/helper.js
25 notice 4.3kB /lib/lib.js
25 notice 1.1kB /LICENSE
25 notice 638B  /package.json
25 notice 3.4kB /README.md
25 notice 988B  /test/test.js
26 notice === Tarball Details ===
27 notice name:          json-to-plain-text
27 notice version:       1.0.3
27 notice filename:      json-to-plain-text-1.0.3.tgz
27 notice package size:  4.1 kB
27 notice unpacked size: 15.8 kB
27 notice shasum:        886d5f0bfcdf85d3755e3dcfc4c7efab1168b9be
27 notice integrity:     sha512-fMvvgpV7nQ1pn[...]Cl4fiZJJbe1rg==
27 notice total files:   11
28 notice
29 http fetch PUT 415 https://registry.npmjs.org/json-to-plain-text 1839ms
30 timing command:publish Completed in 1905ms
31 verbose stack Error: 415 Unsupported Media Type - PUT https://registry.npmjs.org/json-to-plain-text - No package.json found in tarball
31 verbose stack     at /usr/share/nodejs/npm/node_modules/npm-registry-fetch/check-response.js:123:15
31 verbose stack     at async publish (/usr/share/nodejs/npm/node_modules/libnpmpublish/publish.js:43:12)
31 verbose stack     at async publish_ (/usr/share/nodejs/npm/lib/publish.js:120:5)
31 verbose stack     at async publish (/usr/share/nodejs/npm/lib/publish.js:43:19)
32 verbose statusCode 415
33 verbose pkgid json-to-plain-text@1.0.3
34 verbose cwd /home/sumith/repos/json-to-plain-text
35 verbose Linux 5.16.0-12parrot1-amd64
36 verbose argv "/usr/bin/node" "/usr/bin/npm" "publish"
37 verbose node v12.22.5
38 verbose npm  v7.5.2
39 error code E415
40 error 415 Unsupported Media Type - PUT https://registry.npmjs.org/json-to-plain-text - No package.json found in tarball
41 verbose exit 1

遇到同样的问题。这是我的猜测,但我怀疑这是 NPM 注册表服务器端的问题。 'package.json' 显然正在压缩,如 'Tarball Contents' 部分所示。 npm cli 向 NPM 服务器 (registry.npmjs.org) 发出了请求,但出于某种原因,npm 注册表中的代码拒绝了 tarball 并且要么诊断存在 none 的问题,要么告诉我们有问题但误诊。但要更加确定,也许先尝试 'npm pack',然后使用 'tar -tzvf json-to-plain-text-1.0.3.tgz' 检查 tarball 内容,然后 'npm publish json-to-plain-text-1.0.3.tgz'?

Nvm。我现在知道答案了。事实证明 nodejs 12 有点过时了。尝试使用 nodejs v17 使用这个 method. I personally think the Debian repos 是因为太落后了。