npmsassinstallationnpm-init

Solving the 'npm WARN saveError ENOENT: no such file or directory, open '/Users/<username>/package.json'' error


I'm a newbie so please include links to URLs or explain terminologies so I can understand.

I've managed to install 'npm' on a Mac OS (10.13.3) via the terminal, and have installed some packages like SASS using it.

I'm now trying to install sass-mq using npm. I think I've managed to install it, but I'd like a second opinion on what I might have done that was incomplete, or wrong while doing it.

Initially, following the instructions on the sass-mq Github page, I was trying to use:

npm install sass-mq --save

which gave me this error:

npm WARN saveError ENOENT: no such file or directory, open '/Users/<username>/package.json'
    npm WARN enoent ENOENT: no such file or directory, open '/Users/<username>/package.json'
    npm WARN <username> No description
    npm WARN <username> No repository field.
    npm WARN <username> No README data
    npm WARN <username> No license field.

    + sass-mq@5.0.0
    updated 1 package and audited 1 package in 1.67s
    found 0 vulnerabilities

Looking around, I realised I'm meant to be using

npm init

..before typing my 'install sass-mq --save' command.

Cool, done that. Next error was this:

package name: (nikhil) sass-mq
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/nikhil/package.json:

{
  "name": "sass-mq",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "sass-mq": "^5.0.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) 
darwin:~ nikhil$ npm install sass-mq --save
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "sass-mq" under a package
**npm ERR! also called "sass-mq". Did you name your project the same
npm ERR! as the dependency you're installing?**

I think this is saying that I can't use 'sass-mq' (which is the name of the package, as the name of the local package (?) I'm installing into on my local machine. Some more info here.

So I simply tried this:

**package name: (sass-mq) media-queries-nikhil**
version: (1.0.0) 
description: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/nikhil/package.json:

and it seems to have worked OK.

My question is: Is this the right way I should have done this? How do you usually do this?

Also, I get these warnings - is it OK to ignore them?

npm WARN media-queries-nikhil@1.0.0 No description
npm WARN media-queries-nikhil@1.0.0 No repository field.

I'm creating this question in part so others like me looking for the answer to a similar issue can find an explanation, instead of just commands they need to fix their issue. I found a few similar question-threads, but none that actually explained what was happening and why.

Thanks for reading, I really appreciate any help with this :)


Solution

  • You can't name your project equal the package name that you are trying to install.

    Rename your project at the package json and try again or try npm init again and use another name.