对于那些尝试在npm中编写私有模块的人,我按照这些说明进行了操作 - https://docs.npmjs.com/private-modules/intro和https://docs.npmjs.com/getting-started/scoped-packages但是当我需要这样的项目时,我的项目似乎无法找到项目:< / p>
var projectName = require("@username/project-name");
我收到此错误:
找不到模块'@ username / project-name'
我错过了什么或者我做错了什么?我所做的就是遵循上述链接的说明。
虽然我在安装过程中也遇到了一些问题,但我不知道为什么会这样:
npm WARN saveError Problems were encountered
npm WARN saveError Please correct and try again.
npm WARN saveError extraneous: browserify-ngannotate@1.0.1 /home/bassist/Workspace/test/test-web/node_modules/browserify-ngannotate
npm WARN saveError extraneous: browserify-shim@3.8.10 /home/bassist/Workspace/test/test-web/node_modules/browserify-shim
npm WARN saveError extraneous: karma-browserify@4.4.0 /home/bassist/Workspace/test/test-web/node_modules/karma-browserify
npm WARN saveError invalid: have pm2-deploy@0.2.1 (expected: latest) /home/bassist/Workspace/test/test-web/node_modules/pm2/node_modules/pm2-deploy
npm WARN saveError extraneous: pm2-deploy@0.2.1 /home/bassist/Workspace/test/test-web/node_modules/pm2/node_modules/pm2-deploy
npm WARN saveError extraneous: watchify@3.4.0 /home/bassist/Workspace/test/test-web/node_modules/watchify
tv4@1.0.18 node_modules/tv4 -> node_modules/pm2/node_modules/pm2-deploy/node_modules/tv4
test-web@0.2.49 /home/bassist/Workspace/test/test-web
└── @username/project-name@1.0.0
npm WARN optional Skipping failed optional dependency /gulp-nodemon/nodemon/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
npm WARN optional Skipping failed optional dependency /karma/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
npm WARN optional Skipping failed optional dependency /karma-browserify/watchify/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
npm WARN optional Skipping failed optional dependency /pm2/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
npm WARN optional Skipping failed optional dependency /watchify/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
编辑:我再次在我的主应用程序上重新安装了所有node_modules并安装了我的自定义模块,没有任何问题,但仍无济于事。
这是我的package.json内容(在自定义模块上)
{
"name": "@username/project-name",
"version": "1.0.3",
"description": "Separate module which can cater Mongo Data Service, and other services that access the Mongo database",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Simon Guillen <simonbass@gmail.com>",
"license": "ISC"
}
免责声明:我的项目是保密的,这就是为什么我使用@username / package-name作为我的示例范围模块名称。
答案 0 :(得分:1)
我解决了这个问题,问题在于没有将我的代码放在index.js中,因为我需要做的是将多个与数据相关的函数传递给一个包含3个文件的单独模块。所以我不得不在这3个文件上堆积代码并将它们放在我的index.js
上