![](/img/trans.png)
[英]npm install “no such file or directory '…/package.json'” for custom modules
[英]Is it necessary to have a package.json file before I can install npm modules?
我基本上有一個完全空的文件夾,其中有一個文件test.js
。 我想安裝幾個模塊,但是當我嘗試執行類似npm install express
我收到一個錯誤,提示我沒有package.json
文件。
$ npm install express
> node-icu-charset-detector@0.1.3 install /Users/me/node_modules/node-icu-charset-detector
> node-gyp rebuild
CXX(target) Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o
../node-icu-charset-detector.cpp:7:10: fatal error:
'unicode/ucsdet.h' file not found
#include <unicode/ucsdet.h>
^
1 error generated.
make: *** [Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 15.0.0
gyp ERR! command "/usr/local/Cellar/node/5.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/me/node_modules/node-icu-charset-detector
gyp ERR! node -v v5.1.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN install:node-icu-charset-detector@0.1.3 node-icu-charset-detector@0.1.3 install: `node-gyp rebuild`
npm WARN install:node-icu-charset-detector@0.1.3 Exit status 1
/Users/me
├── express@4.13.3
├── UNMET PEER DEPENDENCY react@>=0.14.0 <0.15.0
└── UNMET PEER DEPENDENCY react-dom@>=0.14.0 <0.15.0
npm WARN ENOENT ENOENT: no such file or directory, open '/Users/me/package.json'
npm WARN EPEERINVALID mongoskin@1.4.13 requires a peer of mongodb@~1.4 but none was installed.
npm WARN EPEERINVALID react-router-component@0.28.0 requires a peer of react@>=0.14.0 <0.15.0 but none was installed.
npm WARN EPEERINVALID react-router-component@0.28.0 requires a peer of react-dom@>=0.14.0 <0.15.0 but none was installed.
npm WARN EPEERINVALID react-tap-event-plugin@0.2.1 requires a peer of react@^0.14.0 but none was installed.
npm WARN EPACKAGEJSON me No description
npm WARN EPACKAGEJSON me No repository field.
npm WARN EPACKAGEJSON me No README data
npm WARN EPACKAGEJSON me No license field.
npm install
基本上有三種主要形式:
npm install
:讀取package.json
,並將其中的所有內容安裝到此目錄中。npm install express
:將 express 安裝到此目錄中。npm install --save express
:將 express 安裝到此目錄中,並將其保存到 package.json 中。 第二種形式不需要package.json
存在於此處:
$ npm install express
express@4.13.3 node_modules/express
├── escape-html@1.0.2
├── array-flatten@1.1.1
...
如果您收到錯誤消息,則說明其他地方有問題。
不,不需要 package.json。
您可以在其中包含多個不同的模塊名稱,您要在 npm install 中安裝哪些模塊。
您可以更好地控制模塊的版本
您可以將依賴項和開發依賴項等模塊分開
'npm install express' 會為你安裝 express 模塊。
注意:如果您使用范圍包Scoped Packages恐怕是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.