我已经安装了版本号为"parcel"; "^2.0.0-rc.0"json就像这样当我尝试运行命令npm start时我就是这样的错误我想调用index.html页面,但它显示像文件扩展名必须是。js,。mjs,或。cjs如何解决这个问题?
"name": "receipe-book",
"version": "1.0.0",
"description": "you can get your favourite receipe here",
"main": "index.html",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
},
"author": "Somu Nelavalli",
"license": "ISC",
"dependencies": {
"parcel": "^2.0.0-rc.0"
}```
Server running at http://localhost:1234
× Build failed.
@parcel/core: Unexpected output file type .html in target "main"
H:Somu PracaticeJavascriptcomplete-javascript-course-mastercomplete-javascript-course-master18-forkifystarterpackage.json:5:11
4 | "description": "you can get your favourite receipe here",
> 5 | "main": "index.html",
> | ^^^^^^^^^^^^ File extension must be .js, .mjs, or .cjs
6 | "scripts": {
7 | "start": "parcel index.html",
The "main" field is meant for libraries. If you meant to output a .html file, either remove the "main" field or choose a different target name.
Thanks in Advance
该错误的来源是package.json
中的"main": "index.html"
字段。根据文档,这个字段是为库项目使用的(例如,被其他人使用的npm包)——它告诉parcel在那个位置输出一个commonjs JavaScript包,这对html文件来说没有意义。
因为它看起来不像你在开发一个库,你可以简单地删除"main": "index.html"
,它应该工作得很好(参见迁移文档)。
为非库项目指定输出目录,使用--dist-dir
cli参数代替(参见文档)。
将包中的main
重命名为default
。json文件。
{
"version": "1.0.0",
"description": "",
"default": "dist/index.html"
}