Installed node,运行npm init创建package.json,Installed package。使用npx-package index.html运行服务器将运行服务器。然后我改变了";脚本";至";"开始":"包裹索引.html";在package.json中,并运行npm run start,它还可以毫无问题地运行服务器。然后我加上";脚本"build":"地块构建索引.html";并运行npm-run-build。但这不起作用。。。我得到下面的错误。。。
> vjezba-17@1.0.0 build
> parcel build index.html
× Build failed.
@parcel/namer-default: Target "main" declares an output file path of "index.js" which does not match the compiled bundle type "html".
C:UsersijevrDesktopJavaScriptvjezba 17package.json:4:11
3 | "version": "1.0.0",
> 4 | "main": "index.js",
> | ^^^^^^^^^^ Did you mean "index.html"?
5 | "scripts": {
6 | "start": "parcel index.html",
ℹ Try changing the file extension of "main" in package.json.
当然,将main更改为index.html表示该文件应该是.js文件。。。index.js是npm init在package.json中创建的。在我的文件夹中,我的主js文件名为script.js,在我运行npm init之前,它是这样命名的。然而,将main更改为script.js也没有帮助,我得到了与这里所述相同的错误。。。
我不知道该怎么做npm构建它…
解决这些问题。请从package.json文件中删除"main": "index.js",
。
从这个包.json::
{
"main": "index.js",
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
}
}
到此包.json::
{
"scripts": {
"start": "parcel index.html",
"build": "parcel build index.html"
}
}
https://parceljs.org/getting-started/migration/#package.json%23main
我没有找到修复程序,但我发现使用Parcel 2,构建过程发生了变化。现在工作。
脚本应该是这样的:
"start": "parcel",
"build": "parcel build"
主要来源如下:
"main":"dist/index.js"//dist是构建的路径
"源":"js"//并src我们项目的路径
从package.json
中完全删除main
属性,或将其添加到package.json
:
"targets": {
"main": false
},
对我来说,这很有效https://stackoverflow.com/a/71708198/20383654我按照建议添加了以下内容,构建成功了。"targets": { "main":false },