I published a simple package to npm and it's not working properly when installed. The package.json is as follows
{
"name": "test-package-hello",
"version": "1.0.4",
"description": "This is a test package",
"main": "index.js",
"bin": {
"hello": "index.js"
},
"scripts": {
"test": "exit 0"
},
"author": "Jeril Sebastian",
"license": "MIT",
"dependencies": {
"chalk": "^2.1.0"
}
}
I published the package using npm publish and it gets published successfully. Then I install it using npm install -g test-package-hello and it gets installed successfully.
But when I try to run the program using hello, it gives the error
/home/jeril/.nvm/versions/node/v6.11.3/bin/hello: line 1: syntax error near unexpected token `('
Apparently it's trying to run index.js as a bash script. When I examined other files in /home/jeril/.nvm/versions/node/v6.11.3/bin/, all of them have the this line on top
#!/usr/bin/env node
Where as my package's index.js doesn't have it on top.
What am i missing?
Find the source here and the published package here
Related
I was developing a cli game with npm but ... don't know why, it is showing me an error when I run with npx command. But when I try to install with npm i, it works smoothly
type
npx internet-millionaire
on your cmd and you would see, it will throw an error - "The system can not find the path specified".
I have specified bin and main path on package.json and shebang on top of index.js file is also present. But I don't why...I am still getting error
here is the package : https://www.npmjs.com/package/internet-millionaire
And here is the github repo : https://github.com/ranjanmangla1/internet-millionaire
The package should have the same behavior as
npx firequiz but it is throwing an error.
Would be a great help if someone finds a solution, working on it for last 2 days!
On executing npx internet-millionaire should have the same behavior as npx firequiz.
But it shows a "The system can not find the path specified" error.
Here is the code in the package.json file :
{
"name": "internet-millionaire",
"version": "1.0.11",
"description": "Who wants to be an internet millionaire?",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/ranjanmangla1/internet-millionaire"
},
"main": "index.js",
"scripts": {
"start": "node ."
},
"bin": "./index.js",
"dependencies": {
"chalk": "^5.2.0",
"chalk-animation": "^2.0.3",
"figlet": "^1.5.2",
"gradient-string": "^2.0.2",
"inquirer": "^9.1.4",
"nanospinner": "^1.1.0"
}
}
here is the package : https://www.npmjs.com/package/internet-millionaire
And here is the github repo : https://github.com/ranjanmangla1/internet-millionaire
I have project and i have installed live-server using npm install --save-dev live-server
I want to now run live-server using scripts property in package.json file.
I know we can run it globally but i want to run live-server within the project folder.
i dont know why you want to do that, but you can add this on package.json
"scripts": {
"live": "live-server"
}
and then run with npm like this:
npm run live
here's an example of package.json:
{
"name": "tailwindcss",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"tailwindcss": "^1.4.6"
},
"devDependencies": {},
"scripts": {
"build:css": "tailwind build src/style.css -o style.css",
"live": "live-server"
},
"keywords": [],
"author": "",
"license": "ISC"
}
I've had no problems manually publishing my scoped package to the NPM registry however I found the np module could be used to ensure no steps were skipped in the process.
I've configured only a couple options in my package.json as the defaults are otherwise sensible for me. (This is the package.json for the npm package itself)
{
"name": "#scope/package",
"version": "0.0.6",
"description": "blah",
"main": "index.js",
"scripts": {
"prepublishOnly": "npm run release",
"release": "npm run build:dev && npm run build:prod",
"build:prod": "NODE_ENV=production rollup -c",
"build:dev": "NODE_ENV=development rollup -c",
"test": "echo \"No tests specified\""
},
"repository": {
"type": "git",
"url": "http://blah/blah/blah"
},
"author": "blah",
"license": "ISC",
"devDependencies": {
...
},
"peerDependencies": {
...
},
"np": { <----
"yarn": false, <----
}, <----
"publishConfig": { <----
"access": "public" <----
} <----
}
Unfortunately when I run np I receive the error:
Command failed with exit code 128 (Unknown system error -128): git log --format=%s %h commit sha commit sha..HEAD
The first commit sha is the initial commit from Gatsby.
If you've used Gatsby you may have seen it:
Initial commit from gatsby: (https://github.com/gastbyjs/gatsby-starter-hello-world.git)
For context: I'm creating a component library where the parent dir is setup using GatsbyJS so that I can use it for the demo site while the child dirs under src/packages will be the individual components that will be published to the npm registry. So the demo site is bundled with Gatsby while the packages are bundled using rollup.
Why am I receiving this -128 error code and how do I fix it?
I am building an npm library and published it to npm.
After publishing I am trying to install the library globally.
But it's not working, looks like it's trying to open the file directly
My package.json looks like as follows:
{
"name": "lssomename",
"version": "1.0.4",
"description": "Test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"run": "node index.js"
},
"author": "Test",
"license": "ISC",
"dependencies": {
"command-line-args": "^5.0.2",
"fs": "0.0.1-security",
"ncp": "^2.0.0",
"rimraf": "^2.6.2",
"zip-folder": "^1.0.0"
}
}
As soon as I try to run it throws the following error
/home/thabung/.nvm/versions/node/v8.5.0/bin/lssomename: line 1: $'\r': command not found
/home/thabung/.nvm/versions/node/v8.5.0/bin/lssomename: line 2: syntax error near unexpected token `('
'home/thabung/.nvm/versions/node/v8.5.0/bin/lssomename: line 2: `const log = require("./logger");
The same error comes if try to run directly the index.js file, meaning
when I try
./index.js
instead of
node index.js
Ok the issue was, I need to add an indicator in the begining of the file,
also known as shebang for Unix like systems like as follows
#!/usr/bin/env node
in the beginning of my index.js file & it started working after that.
I'm new to nodejs, working on Webstorm 9.0.1, i'm trying to use Lab module for tests using this tutorial https://medium.com/the-spumko-suite/testing-hapi-services-with-lab-96ac463c490a
My package.json file contains the following :
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/lab/bin/lab -c"
},
"author": "",
"license": "ISC",
"devDependencies": {
"hapi": "^8.0.0",
"joi": "^5.0.2",
"lab": "^5.1.0"
}
}
The local node_modules directory is created in the directory C:\Users\DT002\WebstormProjects\hapiB\test>
the problem is that when i try to test, i got the following error :
> C:\Users\DT002\WebstormProjects\hapiB\test>npm test
>
> test#1.0.0 test C:\Users\DT002\WebstormProjects\hapiB\test
> ./node_modules/lab/bin/lab -c
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Thank you for any suggestions.
The instructions in your scripts runs as a commands in the terminal. You have in your npm test: "./node_modules/lab/bin/lab -c".
What the system is complaining is the first dot that you have there. You can remove the ./ and the error will go away.
{ "test": "node_modules/lab/bin/lab -c" }