我正在使用zombie無頭瀏覽器軟件包編寫CLI utility。節點無法找到模塊(即使已安裝)
最初,我在本地安裝了依賴關係,因爲我需要他們npm install zombie foo bar
和腳本工作得很好。
但由於寫的package.json每次我嘗試安裝或本地運行該腳本,我得到這個模塊錯誤:
$ node index.js
module.js:340
throw err;
^
Error: Cannot find module 'zombie'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/neal/Downloads/cpupdate-exp/index.js:2:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
出現這種情況,無論我再怎麼安裝軟件包。這是沒有意義的。我可以在我的當地node_modules
目錄&中看到他們的一切。
所以我想我的問題是,我的package.json是錯誤的還是我一直搞亂我的節點安裝?
順便說一句,我也嘗試安裝新的殭屍在一個單獨的目錄&運行一個非常簡單的腳本(下同),但我得到同樣的錯誤Cannot find module
。
var browser = require("zombie");
var assert = require("assert");
b = new browser();
b.visit("http://nealshyam.com/", function() {
assert.ok(browser.success);
console.log(browser.text("title"));
});
的package.json:
{
"author": "Neal Shyam",
"name": "cpupdate",
"version": "0.1.1",
"description": "Update your ChallengePost Portfolio with node.js",
"homepage": "http://challengepost.com/software/cpupdate",
"license": "MIT",
"bugs":{
"url":"https://github.com/nealrs/cpupdate/issues",
"email":"[email protected]"
},
"repository": {
"type": "git",
"url": "[email protected]:nealrs/cpupdate.git"
},
"bin": "./index.js",
"keywords": [
"ChallengePost",
"update",
"portfolio"
],
"dependencies": {
"zombie": "assaf/zombie",
"assert": "defunctzombie/commonjs-assert",
"open": "pwnall/node-open",
"colors": "Marak/colors.js",
"nomnom": "harthur/nomnom"
},
"preferGlobal": "true"
}
噢 - 好吧,我沒有瘋狂。謝謝!! – nealrs 2015-02-06 16:04:13