未找到我的自定义 NPM 包 [英] My custom NPM Package is not found

查看:69
本文介绍了未找到我的自定义 NPM 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到非常奇怪的问题.基本上我决定创建我自己的 npm 包,并将它发布到全世界.在开发过程中,我将它作为一个简单的节点模块进行测试,并且能够使用下一个代码来使用它:

Got very strange issues. Basically i decided create my own npm package, and publish it to the world. During development, I was testing it as s simple node module, and was able to use it using next code:

var r = require('./lib/%mymodulename%');

当然是在 lib 文件夹中.

Of course it was in the lib folder.

现在,我将它组织为一个 npm 包,接下来是我的 package.json:

Now, I organised it as a npm package, and my package.json looks next:

{
  "name": "mymodulename",
  "author": "xxx",
  "description": "xxx",
  "version": "0.0.1",
  "homepage": "xxx",

  "repository": {
    "type": "git",
    "url": "xxx"
  },

  "main": "/lib/mymodulename.js",

  "scripts": {
    "install":"node install.js"
  },

  "dependencies": {},
  "engines": {
    "node": ">=0.9"
  }

}

当我尝试通过以下方式对其进行测试时: npm install .-g 它已成功安装,我可以通过以下方式看到我的本地模块:

when i am trying to test it via : npm install . -g it is installed successfully and i am able to see my local module via:

npm ls -g

但是,当我尝试在节点文件中使用它时:

however, when i am trying to use it in node file like:

var r = require('mymodulename') npm 找不到.

我想我遗漏了一些很小的东西,但找不到.

I think that i am missing something very small, but can't find what.

谢谢,-D

推荐答案

好的!感谢您的回答.

这完全是我的错,从来没有把 / 放在 main 中.

It was totally my fault, and never put / for the main.

就我而言,我得到了:

 "main": "/lib/mymodulename.js",

它应该是:

 "main": "lib/mymodulename.js",

谢谢!

这篇关于未找到我的自定义 NPM 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆