【发布时间】:2022-04-01 23:47:52
【问题描述】:
已安装节点,运行 npm init 创建 package.json,安装 parcel。使用 npx parcel index.html 运行服务器运行服务器。然后我将package.json中的“scripts”改为“start”:“parcel index.html”,然后运行npm run start,它也运行服务器没有问题。然后我添加到“脚本”“build”:“parcel build index.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:\Users\ijevr\Desktop\JavaScript\vjezba 17\package.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 构建它...
【问题讨论】: