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
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 installed different packages through npm to run a simple hello world application in React (I am new to it). After their installation, the package.json has this format.
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/theo82"
},
"keywords": [
"test"
],
"author": "Theo Tziomakas",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}
After running the npm start in cmd(windows 8.1),I get this error.
npm ERR! Unexpected token ',' at 6:4
npm ERR! },
npm ERR! ^
In various answers people solved this problem by using a clean cache as
npm cache clean
However,this does not work for me:(. Any ideas why is this happening?
Thanks,
Theo.
There are syntax errors in your file. Also you should specify what your start script should do. For example, when you run npm start node should execute the index.js file
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [
"test"
],
"author": "",
"license": "ISC"
}
The syntax of your package.json have some problem, there is a extra } after the line of the key main
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/theo82"
},
"keywords": [
"test"
],
"author": "Theo Tziomakas",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}
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 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.
I can't figure this out! I'm trying to register a package to bower but it keeps complaining about missing metadata entries and when I install the package it doesn't have the right files.
shell
bower register xxx [git]
bower invalid-meta xxx is missing "main" entry in bower.json
bower invalid-meta xxx is missing "ignore" entry in bower.json
bower.json
{
"name": "xxx-client",
"version": "0.0.9",
"homepage": "https://github.com/xxx/xxx-client",
"authors": [
"Myself <myself#gmail.com>"
],
"description": "client for xxx server",
"keywords": [
"javascript",
"xxx",
"xxx-client",
"js",
"node.js"
],
"license": "MIT",
"main": "dist",
"dependencies": {
"superagent": "~0.21.0"
},
"ignore": [
"**/.*",
"node_modules",
"public",
"bin",
"routes",
"views",
"app.js",
"LICENSE",
"*.md",
"*.json",
"gulpfile.js",
"bower_components",
"public/bower",
"test",
"tests"
]
}