npm run build with Parcel 抛出错误

Igo*_*vic 5 json npm

安装节点,运行 npm init 创建 package.json,安装 Parcel。使用 npx Parcel index.html 运行服务器来运行服务器。然后我将package.json中的“scripts”更改为“start”:“parcel index.html”,并运行npm run start,它也运行服务器没有问题。然后我添加到“scripts”“build”:“parcel build index.html”并运行 npm run build。但这不起作用...\n我收到以下错误...

\n
> vjezba-17@1.0.0 build  \n> parcel build index.html\n\n\xc3\x97 Build failed.\n\n@parcel/namer-default: Target "main" declares an output file path of "index.js" which does not match the compiled bundle type "html".\n\n  C:\\Users\\ijevr\\Desktop\\JavaScript\\vjezba 17\\package.json:4:11\n    3 |   "version": "1.0.0",\n  > 4 |   "main": "index.js",\n  >   |           ^^^^^^^^^^ Did you mean "index.html"?\n    5 |   "scripts": {\n    6 |     "start": "parcel index.html",\n\n  \xe2\x84\xb9 Try changing the file extension of "main" in package.json.\n
Run Code Online (Sandbox Code Playgroud)\n

当然,将 main 更改为 index.html 表明该文件应该是 .js 文件...index.js 是 npm init 在 package.json 中创建的内容。在我的文件夹中,我的主 js 文件名为 script.js,在我运行 npm init 之前它是这样命名的。然而,将 main 更改为 script.js 也没有帮助,我得到与此处所述相同的错误...

\n

我不知道该怎么做才能 npm 构建它......

\n

Igo*_*vic 2

我没有找到修复方法,但我发现 Parcel 2 的构建过程发生了变化。现在可以工作了。

脚本应该如下所示:

"start": "parcel",
"build": "parcel build"
Run Code Online (Sandbox Code Playgroud)

主要和来源如下:

"main": "dist/index.js", //dist 是构建的路径

"source": "src/script.js", //src是我们项目的路径