31

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?

6
  • 1
    In order to create an organization on npm that will allow you to publish packages to your scopes complete steps 1, 2, and 3 on this page: npmjs.com/docs/orgs/getting-started.html May 6, 2017 at 18:52
  • 1
    if you want @npmtestscope, you must a create a npmtestscope organization npmjs.com/docs/orgs May 6, 2017 at 19:33
  • 1
    Not for public repositories. I think the only other thing you have to do, besides registering the organization, is use the --access public flag when you publish for the first time.
    – Ole
    Sep 28, 2018 at 14:06
  • 1
    Organizations on npm can be created here: npmjs.com/org/create - If you have created your organization, then you can publish your namescoped package using npm publish --access public.
    – Benny Code
    Dec 19, 2018 at 0:34
  • 2
    @BennyNeugebauer might as well put that as the answer.
    – Ole
    Dec 19, 2018 at 2:42

1 Answer 1

47

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.

2
  • 2
    Ah, the login part was the necessary step for me, I was logged in with my old account, I needed to update that.
    – PhiLho
    Jan 10, 2021 at 11:17
  • 1
    Thanks so much for the help! I was having a hard time with this scoped packages stuff! Aug 19, 2022 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.