NPM CLI package.json invalid - node.js

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.

Related

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

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

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

node-sass not compiling with npm scripts

So, I am reading this article and following each of the steps described but when I am trying to run npm run scss I get the following error:
This is my .json file :
{
"name": "new-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"scss": "node-sass --output-style compressed -o dist/css src/scss",
"serve": "browser-sync start --server --files 'dist/css/*.css, **/*.html'"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"node-sass": "^4.13.0"
}
}
It does not create the dist file it's supposed to or doesn't do anything else.
Here is what I got.
node -v v12.13.0
npm -v 6.12.0
Please let me know if you need any further information from my setup but it should be the exact same from the article.

Build node.js app using yarn but getting error Command "build" not found

This is my package.json file.
{
"name": "moneymall",
"version": "1.0.0",
"description": "A money mall server app.",
"main": "index.js",
"author": "Anbu Selvan",
"license": "ISC",
"keywords": [],
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"e": "0.0.4",
"express": "^4.16.4",
"mysql": "^2.16.0",
"pug": "^2.0.3",
"yarn": "^1.15.2"
},
"devDependencies": {
"nodemon": "^1.18.10",
"react-scripts": "^2.1.8"
}
}
Run yarn build and get this error.
yarn run v1.15.2 error Command "build" not found. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command
You don't seem to have a script.build key defined in your package.json file. Sample entry for building with webpack library would be:
"scripts": {
"build": "webpack"
}
If you execute yarn run it will show the list of commands which can be run.
Ideally yarn run dev will do the trick of compiling the build
Please re-read the yarn documentation. You don't seem to have a script key declaring what you build script is, and thus Yarn does not know what to load.

Why devDependencies is not installed

I developed a package for example: testlab, and its package.json is:
{
"devDependencies": {
"mocha": "^2.0.0"
},
"name": "#aab/testlab",
"version": "2.6.0",
"description": "example for npm",
"main": ".\\dest\\main.js",
"dependencies": {
"gulp": "^3.9.1",
"gulp-changed": "^1.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"test"
],
"author": "aab <aab#exmaple.com>",
"license": "ISC"
}
Say I included mocha in devDendencies, and then I created a local directory called e.g. c:\example and used
npm install #aab/testlab --only=dev
to get my package under c:\example, but when I looked at c:\example\node_modules, I did not find mocha package is installed. I also tried other command like
npm install #aab/testlab
still no luck. I used NodeJS v4.6.0 and npm 4.0.2. Although nodeJS seems a little old, could any one help me that?
I have seen this happen only when NODE_ENV is set to PRODUCTION. Something else might be setting it.

Resources