簡體   English   中英

npm install 沒有創建 node_modules 文件夾

[英]npm install not creating node_modules folder

我只是想運行 npm install 。 在本地目錄中,並不斷收到這些錯誤:

npm ERR! install Couldn't read dependencies
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "."
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code EISDIR
npm ERR! errno -21
npm ERR! syscall read

npm ERR! eisdir EISDIR: illegal operation on a directory, read
npm ERR! eisdir This is most likely not a problem with npm itself
npm ERR! eisdir and is related to npm not being able to find a     package.json in
npm ERR! eisdir a package you are trying to install.

我所做的就是 cd 進入我的目錄並運行 npm install 。 我也有一個 packages.json 文件。 知道為什么這不起作用嗎??? 編輯:packages.json 文件的內容如下:

{
  "name": "speech-recognition",
 "version": "1.0.0",
 "description": "speech recognition app",
 "main": "application.js",
 "scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "start": "node server.js"
 },
 "author": "Lisa Buch",
 "license": "ISC"
 }

請檢查您的當前目錄。 它應該包含一個具有正確結構和依賴關系的 package.json 文件。

https://docs.npmjs.com/files/package.json

如果您沒有 package.json 文件,則意味着您正在從頭開始創建項目。 在這種情況下,您可以使用以下命令創建 package.json 文件。

npm init

並使用 npm install 命令提供軟件包名稱來安裝軟件包。 例如,如果你想安裝快遞包。 使用以下命令

npm install express --save

這里 --save 選項將使用包及其版本更新您的 package.json 文件。

這個問題似乎是自我描述的:

npm 錯誤! eisdir 並且與 npm 無法找到
package.json 中

這意味着npm install無法在文件夾中找到package.json文件

您可以在文件夾上運行npm init 這將詢問一系列項目設置問題,最后將創建一個 package.json 文件。

然后你可以在文件夾上運行npm install -save-dev來安裝依賴項

npm install --save試試

我通常不會犯這個錯誤,但我在根 package.json 文件中有拼寫錯誤的“依賴項”。 希望它有幫助。

如果您嘗試運行 npm install 的目錄中有 package-lock.json 文件...刪除 package-lock.json 文件並再次運行 npm install,這將生成所需的所有文件和文件夾。

同意@AnthonyAstige - 我遇到了同樣的問題,即沒有創建node_modules文件夾......至少我是這么想的。 在運行npm install express --save之前,我點擊/拖動了我正在使用的文件夾到 VSCode 中。 @brk 讓我查看其他目錄/文件夾,我發現node_modules文件夾的路徑在我的主目錄中,而不是我拖到 VSCode 中的文件夾。

這個故事的寓意……在運行安裝之前,請確保您位於正確的目錄中,也就是您項目的根目錄。 我知道,新手錯誤,但顯然這是一個廣泛討論的話題。

嘗試這些可能的解決方案。

1. Delete the node_modules folder and also delete the package-lock.json 
   file(if already present).
2. Clear the cache using npm cache clean --verify.
3. And then run npm install again.

如果缺少 package.json

   1. run npm init. It will create the package.json file on the fly for you.
   2. After this proceed as written in 1st Solution.

這個錯誤可能是由許多不同的事情引起的。 也許您的全局包以某種方式損壞了。

1 Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. 
  It is a much stable version for development. This should also change your NPM 
  version so that may also help.

2.Delete the package-lock.json file(if already present).

3 Force clear cache npm cache clean --force

4 You can also try clearing your %temp% and %roaming% AppData/npm-cache

5 Run npm install --force.

4 if this error still occurs, consider using another shell.

您可能已經在使用 package.json 的應用程序,只需將其粘貼到新項目中,然后輸入命令 npm install

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM