我正在编写有关VueJS的教程。我对此是完全陌生的,因此请不要完全确定自己在做什么。我遵循了所有说明,安装了所有软件包,这是我在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
但是,每当我尝试按本教程中的说明操作npm run serve
时,它都会显示一条错误消息,指出缺少package.json
:
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'
我检查了,实际上,我的用户文件夹中没有名为package.json
的文件。我只有一个名为package-lock.json
的文件。
[我也注意到,在教程视频中,终端显示类似1: node
的内容,而在我的视频中,我可以看到1: powershell
。这是屏幕截图:
我想念的是什么?谢谢
[按照El的建议,我做了npm init
,并在我的项目文件夹中创建了一个package.json
文件。在内部,我添加了El建议的内容。现在整个package.json
文件如下所示:
{
"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"
}
并且我现在收到此错误:
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?
在项目的根目录中,您需要具有一个JavaScript文件为package.json
的配置文件。为了制作该配置文件,您可以使用npm init
命令,它将询问您有关项目的一些问题。要启动或服务您的项目,您必须具有如下脚本标签:
'scripts':{
'serve': 'node index.js',
}
在package.json
文件中。
然后您可以在项目根目录的命令行中使用npm run serve
。