我創造私人NPM併發布使用sinopia與this如何使用我的私人NPM包在我的主要項目
的。存儲樹的幫助,我的本地NPM倉庫低於
C:\sinopia
\ storage
\privateProj
package.json
privateProj1.0.1.taz
我主要的項目位置,我運行下面的命令
NPM安裝privateProj --save
它將更新的package.json像波紋管
{
"name": "privateprojectClient",
"version": "1.0.0",
"description": "",
"main": "myApp.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"privateProj": "^1.0.1"
}
}
,並以nodemodule文件夾reffer以下IMAG 後來我嘗試運行節點myapp.js 下載privateProj它顯示以下信息
I:\NodeJSProject\privateprojectClient>node myApp.js
module.js:340
throw err;
^
Error: Cannot find module '/node_modules/privateProj'
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> (I:\NodeJSProject\privateprojectClient\myApp.js:5:10)
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)
請幫我解決這個問題。
在privatePro代碼/ app.js是
var db = require('diskdb');
db.connect('./examples/db', ['articles','comments','users']);
var article1 = {
title : 'diskDB rocks',
published : 'today',
rating : '5 stars'
}
var article2 = {
title : 'diskDB rocks',
published : 'yesterday',
rating : '5 stars'
}
var article3 = {
title : 'diskDB rocks',
published : 'today',
rating : '4 stars'
}
db.articles.save([article1, article2, article3]);
var articleComments = {
title: 'diskDB rocks',
published: '2 days ago',
comments: [{
name: 'a user',
comment: 'this is cool',
rating: 2
}, {
name: 'b user',
comment: 'this is ratchet',
rating: 3
}, {
name: 'c user',
comment: 'this is awesome',
rating: 2
}]
}
db.comments.save(articleComments);
var printFruits = function() {
console.log(db.articles.find());
}
// To test the app locally
//npm publishprintFruits(); // << uncomment this
// and run
// $ node app.js
exports.printFruits = printFruits;
感謝您的快速重播。我只有同樣的錯誤。 – 2015-02-05 21:30:41
您可以提供node_modules/privateProj/app.js中的內容的源代碼嗎?你在該文件中使用module.exports嗎? – 2015-02-05 21:33:44
我編輯我的問題,並添加node_modules/privateProj/app.js也 – 2015-02-05 21:36:15