問題描述
package.json 文件在錯誤的文件夾中創建 (package.json file created in the wrong folder)
我正在創建一個應用程序來使用無服務器的 API,並且初始安裝沒問題。npm serverless install
的文件夾之一是 auth‑server
,其中有兩個文件 ‑ handler.js
和 serverless.yml
被創建(除了 .gitignore
)。
幾步之後,我必須安裝 Axios,因為我需要創建一個 POST
請求 API。在 auth‑server 目錄中,我運行了通常的 npm 語法來安裝 Axios,npm install axios
。然而,令我驚訝的是,npm 並沒有在 auth‑server
中創建 package.json
(和 package‑lock.json
)文件 文件夾,但使用了根文件。
我試圖環顧四周,看看問題是否反復出現,但一無所獲。我知道 package‑json
文件是在執行 npm 的目錄文件夾中創建的,因為我已經使用過 axios 幾次。有人可以指出問題可能出在哪裡嗎?提前致謝。
參考解法
方法 1:
In case someone else needs this: I found out that although not in all cases, it is not uncommon that the npm will use the package.json
file of the root folder. As I needed it inside the auth‑server
folder, I simply created another package.json
file inside it (with a pair of curly brackets on it to avoid a parse error code EJSONPARSE
) and saved it. Once I installed Axios one more (npm install axios
) the package.json
file began to be used and added Axios as a dependency.