Reputation: 12329
I'm building a npm package that I want to publish. I followed this instructions and works untill I get to the require
part. I've installed the package with npm install . -g
and I can see it listed when I do npm ls -g
. But when I require it I get
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)
Thats the error from node-repl, but I got the same in different environment with different stacktrace. So, How can I require my package to publish it later? Here are the relevant parts of my package.json
file in case it helps
{
"name": "vue-print",
"description": "Vue plugin to easy print in the web",
"author": "YerkoPalma <[email protected]>",
"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": {
...
}
}
Upvotes: 1
Views: 2777
Reputation: 790
You don't need to install you package as a global package (-g). Just go to your project folder (where you want use vue-print) and run command "npm i vue-print", after that you can use require('vue-print') in this folder
Upvotes: 1