考虑到Node.js包管理器,即npm - 如果发布命令在发布之前执行pack命令或者它是否完全不同,我很好奇?所以,如果我要执行:
npm publish <folder>
Run Code Online (Sandbox Code Playgroud)
它首先执行以下操作:
npm pack <folder>
Run Code Online (Sandbox Code Playgroud)
npm publish没有明确npm pack之前,但不包出现有预期的内容.即; 的内容.tgz,当我执行本地不同npm pack到的内容npm publish. NPM 能够创建具有将包发布到 NPM 注册表的权限的访问令牌,假设您已将包设置设置为“发布访问”中的“需要双因素身份验证或自动化令牌”(因此隐含地要求我认为 2FA 已启用)。
如何使用该令牌进行发布?我检查了npm publish-- 它要求输入 OTP 代码(作为提示或标志)的输出,在我启用 2FA 之前,它再次要求我输入密码。使用固定令牌比启动我的身份验证器应用程序更容易。我可以禁用 2FA,但让令牌正常工作更好。
我正在尝试创建很少有自定义更改的反应组件作为包并发布到 npm 以便其他项目可以通过导入包来使用它们。
我的包是“样本测试”,可在 ( https://www.npmjs.com/package/sample-testing ) 获得。
使用“webpack”和“babel loader”来翻译 jsx 文件。
当我尝试使用此包中的该组件时出现以下错误。
缩小反应错误 #321;访问https://reactjs.org/docs/error-decoder.html?invariant=321获取完整消息或使用非缩小开发环境获取完整错误和其他有用的警告。
只有当我在包内使用材料 ui 组件而不是常规 html 组件时才会出现此错误。
.babelrc
{
"presets": ["react", "env", "stage-0"]
}
Run Code Online (Sandbox Code Playgroud)
wepack.config.js
var path = require("path");
module.exports = {
mode: "production",
entry: {
TButton: "./src/TButton.jsx"
},
output: {
path: path.resolve("lib"),
filename: "[name].js",
libraryTarget: "commonjs2"
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
use: "babel-loader"
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
TButton.jsx
import React from "react";
import TextField from "@material-ui/core/TextField";
class TButton extends …Run Code Online (Sandbox Code Playgroud) 目标
我已手动将开源库发布到registry.npmjs.org,并且我希望将来的版本能够使用GitHub Actions 自动发布。我之前没有 GitHub 操作的经验。
到目前为止我做了什么
我已将标准 GitHub 操作放入 GitHub 为此目的提供的存储库中(未更改)。在最后一行中,它从npmjs.com获取自动化令牌,我已在存储库上将其定义为环境机密NPM_TOKEN。它显示在存储库的秘密页面中。
我面临的错误
Run npm publish
...
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-01-08T00_20_52_834Z-debug.log
Error: Process completed with exit code 1.
Run Code Online (Sandbox Code Playgroud)
尽管进行了大量的网络搜索,但我还是不明白
我尝试了许多不同的文档和教程,以在私有 gitlab 实例上发布范围内的 npm 包。
到目前为止,我已经:
设置一个包含以下内容的 .npmrc 文件:
@<scope>:registry=https://<domain>/api/v4/packages/npm/
//<domain>/api/v4/projects/<id>/packages/npm/:_authToken=<token>
//<domain>/api/v4/packages/npm/:_authToken=<token>
Run Code Online (Sandbox Code Playgroud)
将“publishConfig”添加到“package.json”:
{
"name": "@<scope>/<name>",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"publishConfig": {
"@<scope>:registry": "https://<domain>/api/v4/projects/<id>/packages/npm"
},
"scripts": {
"build": "tsc",
"prepublish": "tsc"
},
"devDependencies": {
"ts-node": "^9.1.1"
}
}
Run Code Online (Sandbox Code Playgroud)
验证 repo 允许存储包:
但是每次我尝试运行npm publishor 时yarn publish,它都会构建、打包但无法发布:
日志文件详细地重复了上面的错误日志。
我正在尝试为内部服务发布一个私有 SDK,并且需要一种发布它的方法,以便只有拥有正确凭据的人才能在他们的项目中安装它。
提供的链接(未找到 - PUT https:// <link...> )重定向到 npmjs.com,我认为这不应该发生,因为我试图将它存储在 Gitlab 上而不是购买组织在 npmjs 上。
我已经在私有域(运行 gitlab 13.9.1)和https://gitlab.com上尝试了这个过程,两者在上面公开的相同存储库配置上都得到了相同的结果。
我错过了一些步骤吗?提前致谢!
我正在制作一个简单的 npm 包,我删除了第一个版本,即 v0.1.0。所以我的包没有 v0.1.0。但我发布了更高版本,最新的是v0.3.0。但是当我执行时npx <package-name>,它没有安装最新版本(v0.3.0)。相反,它会抛出以下错误。

但是当我指定包的版本(npx <project-name>@v0.3.0)时,它就起作用了。
那么如何让 npx 安装明确提到的最新版本呢?
我想开始将npm包发布到作用域.我是否需要注册为范围为用户名的用户?示例如果我创建这样的包:
ole@MKI:~/firstpackage$ npm init
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (firstpackage) @npmtestscope/firstpackage
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /home/ole/deletethis/package.json:
{
"name": "@npmtestscope/firstpackage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建npm vue component library. 我一直在完成所有步骤,但一直停留在npm publish.
请参阅下面的错误屏幕截图,我尝试了一个多小时后无法在 google 上找到解决方案(错误消息不是那么准确恕我直言,或者我可能无法捕捉到它)。
以供参考 package.json
{
"name": "@satyam/vue-components",
"version": "0.1.0",
"main": "./dist/satyam.common.js",
"files": [
"dist"
],
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build-library": "vue-cli-service build --target lib --name satyam ./src/components/index.js",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.4",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.3.0",
"@vue/cli-plugin-eslint": "~4.3.0",
"@vue/cli-plugin-unit-jest": "~4.3.0",
"@vue/cli-service": "~4.3.0",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/test-utils": "1.0.0-beta.31",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1", …Run Code Online (Sandbox Code Playgroud) 我是否正确地认为,发布一个范围内的 npm 包 ( @foo/bar),即使是作为--access=public,也不是免费的?
它会导致Failed PUT 404( 或402) 错误。这是因为需要一个(付费的)npm 组织吗@foo?
更新(2017 年 3 月):Npm 组织现已免费
我尝试实现使用 GitHub Actions 发布和安装包的官方指南:使用细化权限验证包注册表
失败:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com
npm ERR! need auth You need to authorize this machine using `npm adduser`
Run Code Online (Sandbox Code Playgroud)
包.json
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com
npm ERR! need auth You need to authorize this machine using `npm adduser`
Run Code Online (Sandbox Code Playgroud)
.github/workflow/ci.yml
{
"name": "@charneykaye/banana",
"version": "4.0.6",
"repository": "git@github.com:charneykaye/banana",
"description": "made by …Run Code Online (Sandbox Code Playgroud) node.js npm npm-publish github-actions github-package-registry
npm-publish ×10
npm ×9
node.js ×4
gitlab ×1
npm-install ×1
npx ×1
react-native ×1
reactjs ×1
vue.js ×1