I just published my npm package. But now when I install it using sudo npm install package-name -g, it does download the package but does not download its dependencies. I know this because when I execute this package command packagename path/to/folder then shows an error about it dependencies that is Error: Cannot find module 'hound'. Hound is its dependency. Below is my package.json file
{
"name": "package-name",
"description": "description",
"version": "0.1.1",
"homepage": "url",
"author": {
"name": "Name",
"email": "email#gmail.com"
},
"repository": {
"type": "git",
"url": "url to git"
},
"bugs": {
"url": "url/issues"
},
"licenses": [
{
"type": "MIT",
"url": "url to LICENSE-MIT"
}
],
"main": "lib/package-name",
"engines": {
"node": "0.10.32"
},
"devDependencies": {
"hound": "1.0.4",
"async": "0.9.0",
"replace": "0.3.0",
"grunt": "~0.4.5",
"node-dir": "0.1.6"
},
"keywords": [],
"preferGlobal": "true",
"bin": {
"cssimport" : "lib/package-name.js"
}
}
How can I change this so when user install my package then its dependency automatically downloads and starts working?
Hound is set up as a devDepency, it's not going to be installed in a normal install. If you change that to dependencies it will be. If you need certain things as devDependencies to build your package (like grunt), leave them under that key.
Related
I am creating a package in npm for practice purposes. When I publish it succeeds, and when running npm i <myPackage> it installs it in the node_modules.
I can run it as ./node_modules/<myPackage>/src/index.js but why isnt npx <myPackage> working?
My package.json:
{
"name": "",
"version": "1.4.0",
"description": "Get your random quote right there in the terminal.",
"main": "src/index.js",
"repository": {
"type": "git",
"url": ""
},
"keywords": [
"publish",
"learn",
"quotes"
],
"dependencies": {
"chalk": "5.0.1"
},
"type": "module"
}
To run it as a binary, and use the exact same folder structure, just add:
{
...
"main": "./src/index.js",
"bin": {"<CLINameHere>": "./src/index.js" },
...
}
You can put any name in the CLI, for example tsc is for the package typescript (i.e they do not need to be the same).
Then after installing globally or as a binary using npx it will run.
I have an npm module called 'ldap-pool'. This package depends on 'ldapjs' and also '#types/ldapjs', but for some reason when I install 'ldap-pool' into another project, the '#types/ldapjs' package is not being installed.
The above is the problem.
the package.json file for 'ldap-pool' is like so:
{
"name": "ldap-pool",
"version": "0.0.1011",
"description": "LDAP client connection pool",
"main": "index.js",
"types": "index.d.ts",
"typings": "index.d.ts",
"scripts": {
"test": "./#test.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ORESoftware/ldap-pool.git"
},
"keywords": [
"ldap",
"pool",
"client",
"connection",
"ldapjs"
],
"author": "Olegzandr VD",
"license": "ISC",
"bugs": {
"url": "https://github.com/ORESoftware/ldap-pool/issues"
},
"homepage": "https://github.com/ORESoftware/ldap-pool#readme",
"dependencies": {
"chalk": "^1.1.3",
"ldapjs": "^1.0.1"
},
"devDependencies": {
"#types/chalk": "^0.4.31",
"#types/ldapjs": "^1.0.0",
"#types/node": "^7.0.31"
}
}
When I install ldap-pool in another project, I see:
if I hover over the red squiggly, I see:
Does anyone know why the ldapjs typings are not being included when I run
npm install
?
The typings files need to be moved to the dependencies section of the ldap-pool package.json. Any devDependencies for a module will not be downloaded when the module is used as a dependency.
...
"dependencies": {
"chalk": "^1.1.3",
"ldapjs": "^1.0.1",
"#types/chalk": "^0.4.31",
"#types/ldapjs": "^1.0.0",
"#types/node": "^7.0.31"
}
...
I am getting a problem trying to execute a bower install on my project
I am just executing bower install command on my debian OS
but when this is recognizing the dependencies defined on my bower.json.
its got stuck in a part that I dont understand
this is the last part that i see in my command line
"dependencies": {
"angular": {
"endpoint": {
"name": "angular",
"source": "angular",
"target": "^1.0.8"
},
"canonicalDir": "/home/ricco/.cache/bower/packages/060a9fe0e60a0d3d6c9ed350cde03e61/1.5.4",
"pkgMeta": {
"name": "angular",
"version": "1.5.4",
"license": "MIT",
"main": "./angular.js",
"ignore": [],
"dependencies": {},
"homepage": "https://github.com/angular/bower-angular",
"_release": "1.5.4",
"_resolution": {
"type": "version",
"tag": "v1.5.4",
"commit": "b972d5aa130bef5c4d931f22bd11627207ea35ca"
},
"_source": "https://github.com/angular/bower-angular.git",
"_target": ">=1"
},
"dependencies": {},
"nrDependants": 1
}
},
"nrDependants": 1
}
]
}
]
}
}, {
"type": "input",
"message": "Answer",
"name": "prompt",
"level": "prompt"
then there after dislpaying the
{
"type": "input",
"message": "Answer",
"name": "prompt",
"level": "prompt"
it got stuck there for some reason.
This is my bower.json
{
"name": "ng-boilerplate",
"version": "0.3.2",
"devDependencies": {
"angular": "~1.2",
"angular-mocks": "~1.2",
"bootstrap": "~3.1",
"angular-bootstrap": "~0.10.0",
"angular-ui-router": "~0.2",
"angular-route":"1.5.3",
"angular-resource":"1.5.3"
},
"dependencies": {}
}
I experienced the same issue using the Angular boilerplate ngbp.
I solved the issue by removing the following line from my .bowerrc file:
"json": "bower.json"
Alternatively, see the answer below by #NikolaB. which involves adding resolutions to your bower.json instead of removing this line.
When you specify dependencies for your app via Bower, some of the packages might rely on different versions of the same library. You will have to resolve what version of libraries you want in your app.
If you configure you Bower using "json": "bower.json" inside .bowerrc file, Bower will expect those resolutions to be inside bower.json file. This means that you must have "resolutions" property inside bower.json file.
So, you could try adding "resolutions" property into your bower.json:
{
"name": "ng-boilerplate",
"version": "0.3.2",
"devDependencies": {
"angular": "~1.2",
"angular-mocks": "~1.2",
"bootstrap": "~3.1",
"angular-bootstrap": "~0.10.0",
"angular-ui-router": "~0.2",
"angular-route":"1.5.3",
"angular-resource":"1.5.3"
},
"resolutions": {
"angular": "1.2.12"
}
}
I have a private yeoman generator on my gitlab.
After using npm install -g [url_to_my_generator], I found that yo can't recognize it.
But when I clone it to local and then use npm install && npm link, it works fine and appears in "Available Generators".
Here is my generator's package.json
{
"name": "generator-my-generator",
"version": "0.0.1",
"description": "xxx",
"keywords": [
"yeoman-generator",
"generator"
],
"author": {
"name": "xxx",
"email": "xxx",
"url": "xxx"
},
"main": "app/index.js",
"repository": {
"type": "git",
"url": "git+ssh://xxx/generator-my-generator.git"
},
"dependencies": {
"yeoman-generator": "^0.19.0",
"chalk": "^1.0.0",
"yosay": "^1.0.2"
},
"devDependencies": {},
"files": [
"app"
]
}
And my environments:
OS: Windows 7
yo: 1.4.7
npm: 2.13.5
Thank you for helping.
Two troubleshooting techniques:
Run yo doctor. That's your best friend for any issue with Yeoman.
Make sure the files property of your package.json includes your generators.
I'm creating a module that I want to be installed globally, package.json
{
"name": "my-module",
"description": "My module",
"version": "0.1.0",
"repository": {
"type": "git",
"url": "..."
},
"bugs": {
"url": "..."
},
"files": [
"lib",
"public",
"README.md",
"index.js",
"my-module.js",
"package.json",
"tests"
],
"engines": [
"node >= 0.10.0"
],
"license": "MIT",
"dependencies": {
....
},
"scripts": {},
"devDependencies": {},
"bin": {
"module": "./module.js"
}
}
So I published it to npm registry, after installation (on Windows):
I have incorrect files in global npm modules:
my-module:
"$basedir/node_modules/my-module/my-module.js" "$#"
exit $?
my-module cmd:
"%~dp0\node_modules\my-module\my-module.js" %*
While other installed global packages have more code in their cmd files.
Maybe something wrong with my package json? But I've looked at other module's package.json files and cannot get what is wrong.
I found it, bin module (my-module.js) should contain comment in first line:
#!/usr/bin/env node