目标“main”中出现意外的输出文件类型 .html(^^^^^^^^^^^^ 文件扩展名必须是 .js、.mjs 或 .cjs)

问题描述 投票:0回答:3

我已经安装了版本号为“parcel”的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 Pracatice\Javascript\complete-javascript-course-master\complete-javascript-course-master\18-forkify\starter\package.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
javascript node.js node-modules parceljs
3个回答
4
投票

该错误的来源是

"main": "index.html"
中的
package.json
字段。根据文档,该字段旨在由库项目使用(例如由其他人使用的npm包) - 它告诉parcel在该位置输出commonjs JavaScript包,这对于html来说没有意义文件。

由于您似乎没有在开发库,因此您可以简单地删除

"main": "index.html"
,它应该可以正常工作(请参阅迁移文档)。

要指定非库项目的输出目录,请使用

--dist-dir
cli 参数(参见文档)。


2
投票

在 package.json 文件中将

main
重命名为
default

{
  "version": "1.0.0",
  "description": "",
  "default": "dist/index.html"
}

0
投票

只需将 main 重命名为默认即可正常工作

{ “版本”:“1.0.0”, “描述”:“你自己的”, “默认”:“index.html” }

© www.soinside.com 2019 - 2024. All rights reserved.