Nodejs npm init error

I am trying to install Express with Node. I’ve been following some tutorials, which tell me I need to create a JSON package first by typing npm init into the command prompt. When I do this, I get errors that say npm ERR! code EINVALIDTAGNAME and tags may not have any characters that encodeURIComponent encodes.


This doesn’t happen in the tutorials I’ve watched and I’m having trouble finding the problem online. Does anyone know how I can fix this problem?

npm init takes your current folder name and tries to use it for the package name. But package names can’t have spaces. Your current folder (“Alioune Yague”) has a space so it gives and error. So, it just leaves the name blank. You can add in a name later by editing the package.json.

Or create a folder that has no spaces in its name and do your init there.

I guess I was a little wrong. It doesn’t just leave the name blank but bombs the rest of the init. So you can either do it it a folder that has a “proper” name or create the “package.json” manually.

I’m always cautious about using spaces and special characters in folder and file names - some programs still don’t play well with them.

Hi!

Try the command:
npm init --yes

That just auto-fills the basic info in package.json, it will do nothing to fix the issue (which is because you can’t have spaces in package names, as explained).

Hello Alioune01,

I have managed to replicate your error by having a folder name with space. Try to rename your folder name to either using “-” or “_” and try npm init again. Hope this helps .