Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

For more information on how Google's third-party cookies operate and handle your data, see: Google Privacy Policy

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

#npm

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

If you need a website or want to collaborate, contact me or find our more.

Author: Radu

Pay once, use forever—get huge lifetime software deals on ProductCanyon • Ad

I wanted to update one of my websites 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.

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.

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

If this post helped you, please consider following me on Bluesky or Instagram to support me.

Also, don't hesitate to contact me if you're interested in my web design services, want to collaborate, or just have something to say.

About Radu

I've been working online from home for over 11 years, gaining valuable experience and developing a wide range of skills, including web design and development, optimization, and SEO.

More posts