简体   繁体   English

npm 从终端安装错误

[英]npm install error from the terminal

I am trying to install node in my mac.. i am getting the following error... i downloaded the node from node site and ran that package... can you guys tell me why i am facing that errror..when i do npm install我正在尝试在我的 mac 中安装节点。我收到以下错误...我从节点站点下载了节点并运行了 package...你们能告诉我为什么我会遇到那个错误吗..当我这样做时npm 安装

MacBook-Pro:~ Raj$ npm install
npm ERR! install Couldn't read dependencies
npm ERR! package.json ENOENT, open '/Users/Raj/package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/Raj
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /Users/Raj/package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Raj/npm-debug.log
npm ERR! not ok code 0

Running just "npm install" will look for dependencies listed in your package.json.仅运行“npm install”将查找 package.json 中列出的依赖项。 The error you're getting says that you don't have a package.json file set up (or you're in the wrong directory).您收到的错误表明您没有设置 package.json 文件(或者您位于错误的目录中)。

If you're trying to install a specific package, you should use 'npm install {package name}'.如果你尝试安装一个特定的包,你应该使用'npm install {package name}'。 See here for more info about the command.有关该命令的更多信息,请参见此处

Otherwise, you'll need to create a package.json file for your dependencies or go to the right directory and then run 'npm install'.否则,您需要为您的依赖项创建一个package.json文件,或者转到正确的目录,然后运行“npm install”。

I had this problem when trying to run 'npm install' in a Terminal window which had been opened before installing Node.js.我在尝试在安装 Node.js 之前打开的终端窗口中运行“npm install”时遇到了这个问题。

Opening a new Terminal window (ie bash session) worked.打开一个新的终端窗口(即 bash 会话)有效。 (Presumably this provided the correct environment variables for npm to run correctly.) (大概这为 npm 正确运行提供了正确的环境变量。)

在我的情况下,这是由于其中一个依赖项的 URL 错误( http://而不是git:// ,最后没有.git )。

You're likely not in the node directory.您可能不在节点目录中。 Try switching to the directory that you unpacked node to and try running the command there.尝试切换到解压节点的目录并尝试在那里运行命令。

如果它对其他人有帮助 - 我的问题是一个新手错误,我的 package.json 的名称行中有一个空格,它导致依赖项不可读。

I came across this, and my issue was using an older version of node (3.X), when a newer version was required.我遇到了这个问题,当需要更新版本时,我的问题是使用旧版本的节点(3.X)。

The error message actually suggested this as well:错误消息实际上也暗示了这一点:

...
Make sure you have the latest version of node.js and npm installed
...

So the solution may be as simple as upgrading node/npm.所以解决方案可能就像升级 node/npm 一样简单。 You can easily do this using nvm , the "Node Version Manager"您可以使用“节点版本管理器” nvm 轻松完成此操作

After you've installed nvm , you can install and use the latest version of node by simply running this command:安装nvm后,您只需运行以下命令即可安装和使用最新版本的节点:

nvm install node

For example:例如:

$ nvm install node                                                             
Downloading https://nodejs.org/dist/v8.2.1/node-v8.2.1-darwin-x64.tar.xz...
######################################################################## 100.0%
Now using node v8.2.1 (npm v5.3.0)

$ node --version                                                               
v8.2.1

In mac you might have downloaded and installed Node js in /Users/yourusername/Downloads/nodejs-todo-master , so go here and run npm install command, no need of sudo as well., you should get output like this...在 mac 中,你可能已经在 /Users/yourusername/Downloads/nodejs-todo-master 中下载并安装了 Node js,所以去这里运行 npm install 命令,也不需要 sudo。你应该得到这样的输出......

underscore@1.4.4 node_modules/underscore

ejs@0.8.8 node_modules/ejs

redis@0.8.6 node_modules/redis

jasmine-node@1.0.28 node_modules/jasmine-node
├── walkdir@0.0.7
├── coffee-script@1.8.0 (mkdirp@0.3.5)
├── requirejs@2.1.15
└── jasmine-reporters@1.0.1 (mkdirp@0.3.5)

express@3.0.6 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── range-parser@0.0.4
├── cookie-signature@0.0.1
├── buffer-crc32@0.1.1
├── cookie@0.0.5
├── commander@0.6.1
├── mkdirp@0.3.3
├── debug@2.1.0 (ms@0.6.2)
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.2 (pause@0.0.1, bytes@0.1.0, formidable@1.0.11, qs@0.5.1)

This is all because you are not in the desired directory.这都是因为您不在所需的目录中。 You need to first get into the desired directory.您需要首先进入所需的目录。 Mine was angular-phonecat directory.我的是 angular-phonecat 目录。 So I typed in cd angular-phonecat and then npm install .所以我输入了cd angular-phonecat然后npm install

首先从https://github.com/npm/read-package-json下载 json 包文件,然后从终端运行npm install

For me I was getting the same error and it got resolved after I downgraded my npm and node version. 对我来说,我遇到了同样的错误,我降级了npm和node版本后,它得到了解决。 As I was running an application from git so they 当我从git运行应用程序时,他们

npm install -d --save worked for me. npm install -d --save为我工作。 -d flag command force npm to install your dependencies and --save will save the all updated dependencies in your package.json -d flag 命令强制 npm 安装您的依赖项, --save会将所有更新的依赖项保存在您的package.json

For me I'm on windows 10 X64...对我来说,我在 Windows 10 X64 上...

  • My code npm install on cmd failed我在 cmd 上的代码npm install失败

  • So instead of npm i used Yarn所以我使用Yarn而不是npm

  • Just type yarn install instead of npm install只需输入yarn install而不是npm install

  • This fixed my problem.Tried for 2 days finally found the best solution这解决了我的问题。尝试了 2 天终于找到了最好的解决方案

  • To install yarn , on cmd enter the following code要安装 yarn ,在 cmd 上输入以下代码

  • npm install --global yarn

  • To check if it has installed correctly enter the following code要检查它是否已正确安装,请输入以下代码

  • yarn --version

嘿,如果您发现错误并且在安装时卡住了,那么试试这个 打开运行并输入 %Temp% 并删除所有文件 然后在运行应用程序上输入 prefetch 并删除所有文件然后尝试

If someone is in my situation facing this error and have tried all the above solutions, like:如果有人在我的情况下面临此错误并尝试了上述所有解决方案,例如:

  • you are in the right directory你在正确的目录中
  • you have a package.json file,你有一个 package.json 文件,
  • the JSON is valid, JSON 有效,
  • you have tried to run %temp%您已尝试运行 %temp%
  • you have tried " npm install -d --save" etc.您已经尝试过“ npm install -d --save”等。

Mine worked by doing "npm install --force"我的工作是通过“npm install --force”

Note: This was also recommended in the error itself, which I didn't pay attention to earlier.注意:这个错误本身也是推荐的,之前没注意。

Even " Yarn install" worked.甚至“纱线安装”也有效。

These Will do the Job这些将完成工作

npm install -g yarn
yarn install

or要么

npm install --force

Hey if you found error and stcuk while installing packages ,getting only three files like json file ,lock file and module file using yarn then try this using yarn.嘿,如果您在安装软件包时发现错误和 stcuk,使用 yarn 只获取 json 文件、锁定文件和模块文件等三个文件,然后使用 yarn 尝试此操作。 Open run and type %Temp% and delete all file Then type prefetch on run app an delete all files Then type on CMD npx create -react-app it will give you all packages打开运行并输入 %Temp% 并删除所有文件 然后在运行应用程序上输入 prefetch 并删除所有文件 然后在 CMD 上输入 npx create -react-app 它会给你所有的包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM