npm install gives error “can't find a package.

2019-02-01 15:29发布

npm install / npm install -g command is not working in Windows 7

Node.js is installed properly, node.js version is v0.10.28

Couldn't read dependencies
ENOENT, open '"filepath"\package.json'
This is most likely not a problem with npm itself.
npm can't find a package.json file in your current directory.

Photo

标签: node.js npm
8条回答
来,给爷笑一个
2楼-- · 2019-02-01 16:08

Use below command to create a package.json file.

npm init 
npm init --yes or -y flag

[This method will generate a default package.json using information extracted from the current directory.]

Working with package.json

查看更多
走好不送
3楼-- · 2019-02-01 16:25

In my case there was mistake in my package.json:

npm ERR! package.json must be actual JSON, not just JavaScript.

查看更多
Deceive 欺骗
4楼-- · 2019-02-01 16:27

node comes with npm installed so you should have a version of npm, however npm gets updated more frequently than node does, so you'll want to make sure it's the latest version.

sudo npm install npm -g

Test: Run npm -v. The version should be higher than 2.1.8.

npm install

THAT'S IT!

https://www.youtube.com/watch?v=wREima9e6vk

查看更多
爷、活的狠高调
5楼-- · 2019-02-01 16:28

You don't say what module you want to install - hence npm looks for a file package.json which describes your dependencies, and obviously this file is missing.

So either you have to explicitly tell npm which module to install, e.g.

npm install express

or

npm install -g express-generator

or you have to add a package.json file and register your modules here. The easiest way to get such a file is to let npm create one by running

npm init

and then add what you need. Please note that this does only work for locally installed modules, not for global ones.

A simple example might look like this:

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
    "express": "4.0.0"
  }
}

or something like that. For more info on the package.json file see its official documentation and this interactive guide.

查看更多
混吃等死
6楼-- · 2019-02-01 16:29

>> For Visual Studio Users using Package Manager Console <<

If you are using the Package Manager Console in Visual Studio and you want to execute:

npm install and get:

ENOENT: no such file or directory, open 'C:\Users...\YourProject\package.json'

Verify that you are executing the command in the correct directory.

VS by default uses the solution folder when opening the Package Manager Console.

Execute dir then you can see in which folder you currently are. Most probably in the solution folder, that's why you get this error. Now you have to cd to your project folder.

cd YourWebProject

Now npm install should work now, if not, then you have another issue.

查看更多
7楼-- · 2019-02-01 16:30

I'm not sure what you're trying to do here:

npm install alone in your home directory shouldn't do much -- it's not the root of a node app, so there's nothing to install, since there's no package.json.

There are two possible solutions:

1) cd to a node app and run npm install there. OR

2) if you're trying to install something as a command to use in the shell (You don't have a node application), npm install -g packagename. -g flag tells it to install in global namespace.

查看更多
登录 后发表回答