对于那些尝试在 npm 中编写私有(private)模块的人,我遵循了这些说明 - https://docs.npmjs.com/private-modules/intro和 https://docs.npmjs.com/getting-started/scoped-packages但当我像这样需要它时,我的项目似乎找不到该项目:
var projectName = require("@username/project-name");
我收到此错误:
Cannot find module '@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 作为我的示例范围模块名称。
最佳答案
我解决了这个问题,问题在于没有将我的代码放在index.js中,因为我需要做的是将多个与数据相关的函数传输到一个包含3个文件的单独模块。所以我必须将这 3 个文件的代码堆积起来并将它们放在我的 index.js 中
关于javascript - 安装后找不到 Node 私有(private)模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35170099/