如何发布NPM Scoped Packages/NPM范围未找到?

Ole*_*Ole 8 node.js npm npm-publish

我想开始将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 this ok? (yes) 

    ole@MKI:~/firstpackage$ touch README.md
    ole@MKI:~/firstpackage$ npm publish
Run Code Online (Sandbox Code Playgroud)

这是结果:

npm ERR! 404 Scope not found : @npmtestscope/firstpackage
Run Code Online (Sandbox Code Playgroud)

那么为了让npm找到范围,我还需要做些什么呢?

Ben*_*uer 9

如果要使用名称在npm上发布软件包@npmtestscope/firstpackage,则需要确保名称空间@npmtestscope存在于npm上。要创建该名称空间,您需要在npm创建一个名称为的组织npmtestscope

创建组织后,可以发布@npmtestscope/firstpackage通过执行命名的包npm publish --access public

注意:要运行npm publish属于npm组织的软件包,您需要以该组织的成员身份登录计算机。您可以执行来做到这一点npm login。该npm whoami命令将显示与当前登录名关联的用户名。

  • 啊,登录部分对我来说是必要的步骤,我是用旧帐户登录的,我需要更新它。 (2认同)