0

对于那些尝试在 npm 中编写私有模块的人,我遵循了这些说明 - https://docs.npmjs.com/private-modules/introhttps://docs.npmjs.com/getting-started/scoped-packages但是当我需要这样的项目时,我的项目似乎找不到该项目:

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 作为我的示例范围模块名称。

4

1 回答 1

1

我解决了这个问题,问题在于没有将我的代码放在 index.js 中,因为我需要做的是将多个与数据相关的函数传输到一个包含 3 个文件的单独模块。所以我不得不将这 3 个文件的代码堆积起来,并将它们放在我的 index.js 中

于 2016-02-10T03:51:32.247 回答