cant install discord.js in visual studio code - node.js

I am a new programmer and I don't really understand that much in node.js or any of these things.
My main problem isn't a code bug itself rather not being able to install discord.js in Visual Studio Code.
The command I tried to run is "npm install discord.js" in the terminal and in cmd but both didn't work for me.
The output:
npm ERR! path C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\node_modules\unique-filename\package.json
npm ERR! Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\node_modules\unique-filename\index.js'. Please verify that the package.json has a valid "main" entry
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dezkah\AppData\Roaming\npm-cache\_logs\2020-10-11T14_35_47_984Z-debug.log
I did install the package.json file
{
"name": "bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sorry if this question is stupid or something but I can't seem to find a solution.
Thanks in advance!

The first thing you have to after selecting an empty folder in vscode as worskpace is open a terminal, write and follow instructions
npm init
or npm init --yes for insert all default values.
this generate a package.json inside your working folder.
After that you can install packages via npm
npm i discord.js --save

It's working fine on Windows OS. I created a new package.json file and then installed discord.js.
Will you please clear the cache and then try again?
npm cache clean --force
Then try to install discord.js again:
npm i discord.js

Related

Git Error -4058 while trying to npm install nw-builder

I just created a new folder on my Desktop and loaded it to VSCode so I can start building/learning about NW.js. The first thing I've done was to open VSCode Terminal and execute npm init -y, then I've proceeded to run npm install nw#sdk. No error whatsoever.
Now my new folder has a package.json, a package-lock.json, and node_modules folder.
package.json content:
{
"name": "rename-merra-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nw": "^0.62.1-sdk"
}
}
When I try to run npm install nw-builder --save-dev as the reference suggests # https://www.npmjs.com/package/nw-builder, I got the following error:
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Misharin\AppData\Local\npm-cache\_logs\2022-03-23T03_41_13_504Z-debug-0.log
The .log file can be found here: https://pastebin.com/cZAmugRF
I've tried the following:
Restart VSCode
Restart My Computer
Run npm install (Up to date, 120 packages, version 8.5.5)
Run npm outside VSCode, directly on the prompt (same error)
Delete package-lock.json
Reinstall NodeJS (17.8.0)
Install an older version of NodeJS (17.7.1)
Search for node.js running in the background (there is none)
Disable Windows Security
Run npm cache clear --force
Does anyone have any idea how to solve this error?
Maybe one of the git links (https://registry.npmjs.org/nw-builder) from the nw-builder package is down/offline? In that case, is there any way around it so I can start building with nw.js?
Thank you for your help!
Make sure you have Git installed:
https://git-scm.com
You'll likely want to change your code to:
"devDependencies": {
"nw": "0.62.1-sdk"
}
The ^ can download the normal version if it was published after the sdk version.
I haven't used nw-builder, but from my understanding, it hasn't received any updates in several years. There is a GitHub issue related to this:
https://github.com/nwjs-community/nw-builder/issues/530
Finally, here are instructions for how to manually create your own build:
https://gitlab.com/TheJaredWilcurt/battery-app-workshop
More tutorials are at:
https://nwutils.io

Getting Error While starting lite-server in npm

i did a fresh "npm init". put entry point : "index.html"
then installed lite-server : npm install lite-server --save-dev
also updated the package.json and I Uninstalled, reinstalled tried everything but it's not working and
also tried npm cache clean --force but it's not working. can any one help with this error.
{
"name": "git-test",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run lite",
"lite": "lite-server"
},
"author": "Sateesh",
"license": "ISC",
"dependencies": {
"lite-server": "^2.5.4"
}
}
But when I did "npm start" , getting this error
git-test#1.0.0 start D:\Coursera\git-test
> npm run lite
'npm' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! git-test#1.0.0 start: `npm run lite`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the git-test#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sai\AppData\Roaming\npm-cache\_logs\2020-06-05T10_20_11_723Z-debug.log
I was too facing the same issue after a system shutdown, hence this worked for me:
First uninstall the current local lite-server in node_modules
npm uninstall lite-server
Install lite-server globally and try running the same command
npm install -g lite-server
then hit:
npm start
This fixed the issue for me, thank you
Here's my Json file script if you want to have a look
"scripts": {
"start": "npm run lite",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server"
},
You don't seem to have node/npm installed and configured properly (PATH issues).
I would suggest you try to re-install Node.js using the official instructions for your platform (https://nodejs.org/en/download/) or by using a Node.js version manager like nvm (https://github.com/nvm-sh/nvm) or n (https://github.com/tj/n).
Using nvm or n, will allow you to dynamically switch Node.js version without having to re-install everything from scratch.
Just install the live-server globally,i think that should solve the issue.
sudo npm install --global lite-server
And in your package.json file you can change a little bit.
{
"name": "git-test",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server",
},
"author": "Sateesh",
"license": "ISC",
"dependencies": {
"lite-server": "^2.5.4"
}
}
After this run this on terminal
npm start
I think this should help :)
I had a similar issue,yarn start worked for

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'

I'm doing a tutorial on VueJS. I am completely new to this, so not enitrely sure what I am doing.
I followed all instructions, installed all packages, here is the check I made in terminal in VSCode:
PS C:\Users\...\Documents\Vue - Getting Started> node --version
v12.18.0
PS C:\Users\...\Documents\Vue - Getting Started> npm --version
6.14.5
PS C:\Users\...\Documents\Vue - Getting Started> vue --version
#vue/cli 4.4.1
However, whenever I try to npm run serve as it's shown in the tutorial, it shows an error stating that a package.json is missing:
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'
I checked, and indeed, I don't have a file called package.json in my user folder. I only have a file called package-lock.json.
I also noticed, that on the tutorial video, the terminal has something like 1: node, while in mine, I can see 1: powershell. Here is the screenshot:
screenshot from terminal
What am I missing? Thank you
As suggested by El, I did npm init and created a package.json file in my project folder. Inside, I added the bit suggested by El. The whole package.json file now looks like this:
{
"name": "package.json",
"version": "1.0.0",
"description": "package json",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "node index.js"
},
"author": "",
"license": "ISC"
}
And I am now getting this error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package.json#1.0.0 serve: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the package.json#1.0.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
I think there's no need to explain Nodejs ENOENT error with such a self-explanatory error message: no such file or directory which simply means index.js or any file that you want to run with npm or node isn't in the current directory.
First you need to check to see if you are in the root of your project then in the root of your project you need to have a config file that is package.json for JavaScript(Nodejs, react, typescript and so on) projects.
So for making that config file you can use npm init command and it will ask you predefined questions about your projects.
for starting or serving your project you must have a script tag like this in your package.json file:
'scripts':{
'serve': 'node index.js',
}
then you can use npm run serve command in the root of your project to run serve command of your package.json file.
In case of VueJS, which I am not familiar with, I think you have a index.html file in the root directory of your project and aslo as I know you have vue installed on your machine. I guess you need to replace node index.js with following command to serve your Vue application:
'scripts':{
'serve': 'vue index.html',
}
and run npm run serve.
I fixed this problem with those commands:
// Locate to the folder, where the "node_modules" directory is stored
rm node_modules
npm i
deleted the project folder and then creating vue project
vue create my-project
This is how it worked for me

Getting Error in Project during start project with Npm start, Project created with create-react-app

I am using ubantu 16 OS and i have installed
Node version v10.13.0 and npm version 6.4.1
I am creating Reactjs project based on create-react-app.
I have created project using command
sudo npm init react-app my-app
This command successfully created my-app, but when i am running project using npm start
command under my-app folder i am getting following error
> my-app#0.1.0 start /home/karan/workspace/1425/my-app
> react-scripts start
There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"babel-jest": "23.6.0"
Don't try to install it manually: your package manager does it automatically. However, a different version of babel-jest was detected higher up in the tree:
/home/karan/workspace/node_modules/babel-jest (version: 22.4.4)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /home/karan/workspace/node_modules/babel-jest is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-jest in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-jest.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! my-app#0.1.0 start: `react-scripts start` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the my-app#0.1.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
As this is showing issue related
react-scripts start ,"babel-jest": "23.6.0"
but i am new to js framework(node/npm/react), how this problem will resolve please help?
package.json
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Even though you're receiving an ELIFECYCLE error and not an EACCES, maybe it's something related to the fact that you used sudo to run the command. Try to create and run the project again, without sudo.
Follow this guide for more details on how to do it.

`npm start` complains "missing script: start", without running node

I have the following files in my NPM package:
package.json:
{
"name": "npm-start",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
index.js
console.log('Hello world!');
When I try to run npm start, I get an error message:
> npm start
npm ERR! missing script: start
Okay, it's true: I don't have a "start" property in "scripts" object. But NPM's CLI Documentation claims this about npm start:
If no "start" property is specified on the "scripts" object, it will run node server.js.
Why is NPM failing me? Isn't it supposed to invoke node in this scenario? Am I missing something? (Of course, manually invoking node works fine).
In case it's relevant:
> npm -version
5.3.0
As soon as I finished typing the question, I realized my error.
When "start" property is absent, NPM will invoke node with server.js. But I don't have a server.js. NPM checks under the hood for this server.js file, and fails if it's not present. Ideally though, NPM should have reported that server.js wasn't found. The current way of handling things is confusing.
As soon as you have a server.js file, npm start works fine.
I had this issue as well. I re-installed my npm#4 and my node.js#6.4.0. Then created my project again using the commands
create-react-native-app AwesomeProject
sudo npm start (mac command)
It worked for me!

Resources