npx <package-name> gives "The system can not find the path specified" - node.js

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

Related

NPM CLI package.json invalid

Before posting the issue, I surfed on all possible websites to fix the issue with Node.js- npm cli I am encountering. None of the answers worked for me and I got stuck with. Can someone help to fix it?
The npm cli was running perfectly and it suddenly started to work giving me the traceback Please verify that the package.json has a valid 'main' entry. Even if I re-installed the node.js it has not resolved the issue. (see screenshot below)
The version node.js 16.17.1 on Windows 10
Screenshot:
The content of the package.json
{
"name": "npm-bundled",
"version": "1.1.2",
"description": "list things in node_modules that are bundledDependencies, or transitive dependencies thereof",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/npm-bundled.git"
},
"author": "Isaac Z. Schlueter <i#izs.me> (http://blog.izs.me/)",
"license": "ISC",
"devDependencies": {
"mkdirp": "^0.5.1",
"mutate-fs": "^1.1.0",
"rimraf": "^2.6.1",
"tap": "^12.0.1"
},
"scripts": {
"test": "tap test/*.js -J --100",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},
"files": [
"index.js"
],
"dependencies": {
"npm-normalize-package-bin": "^1.0.1"
}
}
Thanks in advance.
AKA
[Solved]:
Thanks everyone. The problem was lying in the directory C:\Users\your_comp_name\AppData\Local\node & C:\Users\your_comp_name\AppData\Roaming\npm that only needs to be removed to run npm cli further.

Node saying sh: 1: main.js: not found when main.js is there

As the title says, node cannot find main.js. I am doing this through replit and my .replit file is run = "npm test". My package.json file is
{
"name": "Adventure",
"version": "1.0.0",
"description": "This is The Adventure Bot By BrainDead_Dev",
"main": "main.js",
"dependencies": {
"#replit/database": "^2.0.1",
"discord-buttons": "^4.0.0-deprecated",
"discord.js": "^13.6.0",
"moment": "^2.29.1",
"winston": "^3.6.0"
},
"devDependencies": {},
"scripts": {
"test": "main.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/BrainDeadDev/Adventure.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/BrainDeadDev/Adventure/issues"
},
"homepage": "https://github.com/BrainDeadDev/Adventure#readme"
}
This is for a discord bot, and it has been working perfectly fine up until the point where I wanted to update discord.js and had to reinstall npm. Any help would be appreciated as I am quite lost.
When you updated the discord.js package, it now requires a more current version of node js (v16.6).
To update to the version of node using npm simply run:
npm install -g n
If you are using nvm you can do:
nvm install 16.6
then tell nvm to use the new version:
nvm use 16.6
Then you can check the version you are using by running:
node --version
Edit for Repl.it:
following this blog, you should be able to do it by running this:
npm i --save-dev node#16 && npm config set prefix=$(pwd)/node_modules/node && export PATH=$(pwd)/node_modules/node/bin:$PATH
You can also try following this question on repl.it forums

Publishing NPM package with np throws error with exit code 128 (Gatsby & rollup)

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?

Package published to npm not running properly

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

Webstorm,nodejs, npm test, '.' is not recognized as an internal or external command,

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" }

Resources