2024-07-11 npm publish報錯合集

叶乘风發表於2024-07-11

報錯1:This package has been marked as private npm ERR! 你的包被設為私有模式了。

npm ERR! code EPRIVATE
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.

原因:你釋出的包被標記為私有了,如果你想把它公開就必須刪除private欄位。該欄位就在package.json裡面,如下:

解決方案:刪掉private,然後重新執行npm publish。

報錯2:You do not have permission to publish "vite-project". 沒有許可權釋出這個vite-project包。

npm notice Publishing to https://registry.npmjs.org/
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/vite-project - You do not have permission to publish "vite-project". Are you logged in as the correct user?
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.

原因:你的包名在npm官網上已被使用。

怎麼檢視包名?在package.json檔案裡面的name就是你的包名。

解決方案:可以去官網https://www.npmjs.com/search?q=vite-project搜一下你要釋出的報名是否已存在,如果存在了就換一個名字吧,然後再重新執行publish命令。

報錯3: [vite] Internal server error: Failed to resolve entry for package "abc-ui". The package may have incorrect main/module/exports specified in its package.json.

    [vite]內部伺服器錯誤:解析包“日華雲ui”的條目失敗。包的package.json中可能指定了不正確的主/模組/匯出。

原因:這個報錯是因為我的包abc-ui匯出的模組有問題,我檢視並發現了下package.json檔案中的main,module所對應的檔案路徑是不存在的,是不正確的。

解決方案:把匯出包的路徑修改正即可

報錯3:You cannot publish over the previously published versions: 0.0.0. 您不能釋出之前釋出的版本:0.0.0。

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/abc-ui - You cannot publish over the previously published versions: 0.0.0.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.

原因:剛提交完一個包,想要再提一次,就報錯了,因為你再次提交的包的版本號在npm上的包的版本號重複或者相等。

解決方案:修改你的package.json版本號,比如:

把0.0.0改成0.0.1

然後,重新執行publish命令即可。

相關文章