简体   繁体   English

如何从 npm 注册表中删除 npm 包?

[英]How to delete an npm package from the npm registry?

Is there a possible way to remove or delete the entire module from npm registry?有没有可能的方法从 npm 注册表中删除或删除整个模块?

Notice: npm -f unpublish doesn't allowed you to unpublish anything older than 24 hours注意: npm -f unpublish不允许您npm -f unpublish超过 24 小时的任何内容

There's a post about that, given the recent incident.鉴于最近的事件,有一篇关于此的帖子。 Your best bet would be to contact npm and hope that your package isn't depended by other projects.你最好的办法是联系 npm 并希望你的包不被其他项目依赖。

If the version is older than 24 hours, then the unpublish will fail, with a message to contact support@npmjs.com.如果版本早于 24 小时,则取消发布将失败,并发送消息至 support@npmjs.com。

If you contact support, they will check to see if removing that version of your package would break any other installs.如果您联系支持人员,他们将检查删除该版本的软件包是否会破坏任何其他安装。 If so, we will not remove it.如果是这样,我们不会删除它。 You'll either have to transfer ownership of the package or reach out to the owners of dependent packages to change their dependency.您要么必须转让包的所有权,要么与依赖包的所有者联系以更改他们的依赖项。

http://blog.npmjs.org/post/141905368000/changes-to-npms-unpublish-policy http://blog.npmjs.org/post/141905368000/changes-to-npms-unpublish-policy

TL;DR:特尔;博士:

npx force-unpublish package-name 'reason message'

Explanation:说明:

It uses the cli tool force-unpublish which takes the following steps:它使用 cli 工具force-unpublish执行以下步骤:

  1. npm deprecate package-name 'reason message'
  2. npm owner add npm package-name
  3. npm owner rm $(npm whoami) package-name

https://www.npmjs.com/package/force-unpublish https://www.npmjs.com/package/force-unpublish

I stumbled upon this problem where i had to delete an existing package.我偶然发现了这个问题,我不得不删除现有的包。 And the following worked seamlessly.以下工作无缝衔接。 I noticed that the package was removed from my account immediately (It was a test package with no dependency.)我注意到该包立即从我的帐户中删除(这是一个没有依赖项的测试包。)

npm --force unpublish "package-name"

You might have to enter OTP/Auth key if you have configured 2FA on npm account.如果您在 npm 帐户上配置了 2FA,则可能需要输入 OTP/Auth 密钥。

If the published package/version is less than 72 hours old, unless you are the single owner of the module.如果发布的包/版本少于 72 小时,除非您是模块的唯一所有者。

npm unpublish <package-name> --force

https://www.npmjs.com/policies/unpublish has details of the policy to unpublish packages https://www.npmjs.com/policies/unpublish包含取消发布包的政策的详细信息

The command and the policy to unpublish packages may have changed since the question was asked.自提出问题以来,取消发布包的命令和策略可能已更改。

npm force-unpublish package-name 'reason message'

OR

npm --force unpublish "package-name"

did not work for me.对我不起作用。

From the docs: https://www.npmjs.com/policies/unpublish来自文档: https : //www.npmjs.com/policies/unpublish

npm deprecate <package> "<message>" to deprecate the entire package
npm deprecate <package>@<version> "<message>" to deprecate a specific version
If the entire package is deprecated, the package name will be dropped from our search results.

Once deprecated, if you would also like for the package to be removed from your user profile,
it can be transferred to our @npm account. This can be achieved by using the following from your command line:

npm owner add npm <package>
npm owner rm <your_username> <package>

Make sure your package meets the unpublish policy .确保您的包符合取消发布政策

Remove one version删除一个版本

npm unpublish [<@scope>/]<pkg>@<version>

Remove all versions删除所有版本

npm unpublish [<@scope>/]<pkg> --force

https://docs.npmjs.com/cli/v6/commands/npm-unpublish https://docs.npmjs.com/cli/v6/commands/npm-unpublish

It may take a while to take effect after the command is executed successfully on the terminal.命令在终端执行成功后可能需要一段时间才能生效。

Some recent feedback: I've just used the command unpublish <package_name> with --force flag as described by the other guys and it just worked.最近的一些反馈:我刚刚使用了命令unpublish <package_name>和其他人描述的--force标志,它刚刚工作。 The package had been published more than 72h after the removal process.该软件包已在删除过程后72 小时以上发布。

Packaged removed from npm registry (at least from the dashboard...) instantly!立即从 npm 注册表中打包删除(至少从仪表板中...)!

That said, I think it's best to change the currently accepted answer to whoever recommended the command npm unpublish <package_name> .也就是说,我认为最好将当前接受的答案更改为推荐命令npm unpublish <package_name>

Env info:环境信息:

node: 16.6.1
npm: 7.20.3

Happy coding!快乐编码! ._. ._.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM