Fix ‘Sorry, name can only contain URL-friendly characters.’ in npm

I wanted to update my website with some new content, but I needed to compile some more Sass into CSS, and I didn’t want to use ScoutApp anymore.

Since I started learning Laravel, I got used to CLI more.

So, I went ahead and installed node.js to use the npm “node-sass” package.

I followed a guide which said that I had to run npm init, which will prompt some questions.

But I didn’t see anything that looked like a question, so I went ahead and started to spam npm install node-sass and other commands where it requested the package name:. ๐Ÿ™‚

I thought it was requesting the name of the package to install, which was “node-sass” in this case.

Sorry, name can only contain URL-friendly characters npm

But I kept getting this error:

Sorry, name can only contain URL-friendly characters.

While searching for a solution, I saw many people on forums making the same mistake as me ๐Ÿ™‚ . That’s why I decided to write this guide.

The Solution

The solution is simple, and it seems “duh” now that I understood what’s going on. ๐Ÿ™‚

The package name: is actually part of the info requested for the package.json file that is created when running npm init.

package.json node-sass npm

And it requests “URL-friendly characters”, which means you need to name your package using URL-type formatting, like this:

package name: example-package-name

Words separated by hyphens, without capital letters. It might work with only one word, but I haven’t tried that yet.

That’s a Wrap

I hope this post helped you out and you don’t get the “Sorry, name can only contain URL-friendly characters.” error anymore.

If you have questions or thoughts, please leave a comment or send me a message using the contact page.

Don’t forget to share the post to help out others!

2 thoughts on “Fix ‘Sorry, name can only contain URL-friendly characters.’ in npm”

  1. I hoped solution worked on me, but it didn’t.
    I’m trying to install a simple package as it is the “mongoose” for me to connect Node.js with MongoDB; but the response I got over and over is the same “URL-friendly characters” thing… and if it is something about syntax, have no idea.
    I read that you don’t know about a case like this (one word package), but here I go.
    Could you give me a hand please?
    Thank you!

    Reply
    • I don’t know what could be the problem, but you can do one of the following things:

      • Run npm init -y, which will initialize the package.json file with default values. You won’t have to go through them. You can always change them manually later, in the file;
      • Don’t run npm init at all. Just install the package. You can manually create a package.json file later, if you want.
      Reply

Leave a Comment