跳到主要內容

發表文章

目前顯示的是有「node_modules」標籤的文章

npm i fail - 查不出原因的處理方式

npm i fail - 查不出原因的處理方式 經歷許多次的 npm 安裝問題,目前有幾種不同的解法。 npm cache issue 可能因為 npm 下載的時候,或者因為連線問題導致模組並沒有完整被安裝,但是 npm 的檢查機制就是只要存在就會跳過安裝步驟,因此當遇到安裝完成,但是執行卻無法的時候,可以嘗試著 rm -rf node_modules # install again npm i 如果是在中間就遇到 fail 的狀態,有可能是因為之前連線問題,並沒有將模組安裝成功,但是資料已經存在 npm cache 資料夾裡面,以往都需要找出這個環境設定,環境路徑才能進行移除,不過現在透過 npm cache 可以簡單做到這件事情 npm cache clean rm -rf node_modules npm i npm version issue 另外一種會再安裝的時候跳出錯誤,會顯示為 npm 版本不符合,或者是 node 版本不符合,這個時候就需要進行安裝更新,最簡單方式就是升級 npm . npm i -g npm 缺少套件 通常最常見的就是有些模組需要透過 gcc, g++ 這是最常見的缺少模組問題,以 mac 環境來說直接透過 brew 就可以安裝完成。 brew install gcc brew install g++ # install again npm i 記憶體不足 最後一種就是屬於記憶體不足的狀態,這通常會很難檢查,實際上 npm 也會跳出錯誤,現在的錯誤資訊都已經比較明顯, npm ERR! node v4.4.1 npm ERR! npm v3.8.6 npm ERR! code ENOMEM npm ERR! errno ENOMEM npm ERR! syscall spawn npm ERR! spawn ENOMEM 如果遇到這種狀況,請重新調整記憶體分配,如果是採用 vps, 就看能不能夠 scale up ,讓機器的記憶體提升,就可以解決問題。 後記 以上都是踩過的雷,以及在嘗試許多 node.js 專案時會遇到的問題,我們也經常在摸索中,不過從摸索以及找到答案的過程都繞了許多遠路,希望透過分享可以讓大家更瞭解 npm 錯誤時可以怎麼處理。

[fixed] Sequelize: warning: "a promise was created in a handler but was not returned from it"

Sequelize: warning: "a promise was created in a handler but was not returned from it" problem: when running sequelize, and console display error message below, accroding to sequelize issues, the information dose not effect anything about process. Warning: a promise was created in a handler but was not returned from it at [object Object].Instance.save (/home/tremby/myproject/node_modules/sequelize/lib/instance.js:567:18) at [object Object].Model.create (/home/tremby/myproject/node_modules/sequelize/lib/model.js:1824:6) at [object Object].HasMany.create (/home/tremby/myproject/node_modules/sequelize/lib/associations/has-many.js:533:29) at [object Object].obj.(anonymous function) [as createGameSession] (/home/tremby/myproject/node_modules/sequelize/lib/associations/has-many.js:259:24) at done (/home/tremby/myproject/src/app/routes/myroute.coffee:43:10) at [object Object].<anonymous> (/home/tremby/myproject/src/app/routes/myroute.coffee:58:7) at process...

semver, node package.json, dependency module version operators

semver node package.json, dependency module version operators 之前沒有注意到這個問題,現在 node modules 越來越多,原來在 npm 裡面早就有進行相關的版本管理。可以透過這個頁面看到詳細的描述資訊。 The semantic versioner for npm 特別要介紹的部份是, ^ 字元與版本關係 ^ 表示可以進行兼容模式,當第一個非 0 數字被符合之後,就會此此版本安裝。當可安裝版本為 > 0.1.5 ,此時是會直接使用 0.1.5 這個版本進行安裝。 如果一開始使用非 0 數字為版本,就會變成兼容模式,會去尋找符合第一個數字的版本,其他小數字本版號視為可以兼容。 目前 npm install node_modules --save 會採用 ^ 這個符號。 ^0.1.3 := >=0.1.3-0 <0.2.0-0 "Compatible with 0.1.3". 0.x.x versions are special: the first non-zero component indicates potentially breaking changes, meaning the caret operator matches any version with the same first non-zero 另外一種版本 ^1.2.3 := >=1.2.3-0 <2.0.0-0 "Compatible with 1.2.3". When using caret operators, anything from the specified version (including prerelease) will be supported up to, but not including, the next major version (or its prereleases). 1.5.1 will satisfy ^1.2.3, while 1.2.2 and 2.0.0-beta will not. ~ 字元與版本關係 版本需要數字符合,例如底下的例子...