Reputation: 173
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:
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! [email protected] serve: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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?
Upvotes: 4
Views: 28686
Reputation: 164
deleted the project folder and then creating vue project
vue create my-project
This is how it worked for me
Upvotes: 0
Reputation: 1
I fixed this problem with those commands:
// Locate to the folder, where the "node_modules" directory is stored
rm node_modules
npm i
Upvotes: 0
Reputation: 1245
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
.
Upvotes: 6