不能要求npm包

时间:2016-04-13 16:01:05

标签: node.js npm

我正在构建一个我要发布的npm包。我跟着this instructions继续工作,直到require部分。我已经使用npm install . -g安装了该软件包,我可以在npm ls -g时看到它列出。但是当我需要它时,我得到了

var VuePrint = require('vue-print')
Error: Cannot find module 'vue-print'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at repl:1:16
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)

来自node-repl的错误,但我在不同的堆栈跟踪的不同环境中得到了相同的结果。那么,我如何才能要求我的软件包稍后发布?以下是package.json文件的相关部分,以防它有用

{
  "name": "vue-print",
  "description": "Vue plugin to easy print in the web",
  "author": "YerkoPalma <yerko.palma@usach.cl>",
  "version": "0.1.3",
  "main": "dist/vueprint.js",
  "files": [
    "dist/vueprint.js",
    "src",
    "README.md"
  ],
  "scripts": {
    "build": "cross-env NODE_ENV=production browserify -e src/vueprint.js | uglifyjs -c warnings=false -m > dist/vueprint.js",
    ...
  },
  "browserify": {
    "transform": [
      "vueify",
      "babelify"
    ]
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/YerkoPalma/vue-print.git"
  },
  "bugs": {
    "url": "https://github.com/YerkoPalma/vue-print/issues"
  },
  "dependencies": {
    "vue": "^1.0.0"
  },
  "devDependencies": {
    ...
  }
}

1 个答案:

答案 0 :(得分:1)

您无需将软件包安装为全局软件包(-g)。 只需转到您的项目文件夹(您想要使用vue-print)并运行命令“npm i vue-print”,之后您可以在此文件夹中使用require('vue-print')