Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish NPM Scoped Packages / NPM scope not found?

I want to start publishing npm packages to a scope. Do I need to register as a user with the scope as my user name? Example if I create a package like this:

    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

This is the result:

npm ERR! 404 Scope not found : @npmtestscope/firstpackage

So what do I need to do in order for npm to find the scope?

like image 629
Ole Avatar asked May 06 '17 18:05

Ole


People also ask

What is npm scoped package?

What are Scoped Packages? Scoped Packages is a way to group related npm packages together, and connect them to each other by a specified “scope”, that acts pretty much like a namespace.

What is the default scope of the package publish to npm registry?

Publishes a package to the registry so that it can be installed by name. By default npm will publish to the public registry. This can be overridden by specifying a different default registry or using a scope in the name, combined with a scope-configured registry (see package. json ).

Which of the following commands can be used to create a scoped package in npm?

Run this command to initialize a scoped NPM project: npm init --scope=@<org> using the Org name created above.


1 Answers

If you want to publish a package on npm using the name @npmtestscope/firstpackage, you need to make sure that the namespace @npmtestscope exists on npm. To create that namespace, you need to create an organization on npm with the name npmtestscope.

After you have created the organization, you can publish your package named @npmtestscope/firstpackage by executing npm publish --access public.

Note: To run npm publish for a package that belongs to a npm organization, you need to be logged in on your computer as a member of that organization. You can do that by executing npm login. The npm whoami command will show you the user name associated with the current login.

like image 138
Benny Neugebauer Avatar answered Sep 19 '22 15:09

Benny Neugebauer