【问题标题】:npm run build with parcel throws an errornpm run build with parcel 抛出错误
【发布时间】: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 构建它...

【问题讨论】:

    标签: json npm


    【解决方案1】:

    我没有找到解决方法,但我发现 Parcel 2 的构建过程发生了变化。 现在可以使用了。

    脚本应如下所示:

    "start": "parcel",
    "build": "parcel build"
    

    主要和来源是这样的:

    "main": "dist/index.js", //其中dist为构建路径

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

    【讨论】:

      【解决方案2】:

      package.json 中完全删除main 属性,或将其添加到package.json

      "targets": {
        "main": false
      },
      

      【讨论】:

        猜你喜欢
        • 2018-11-19
        • 2021-03-03
        • 2019-04-09
        • 1970-01-01
        • 2020-10-26
        • 1970-01-01
        • 2021-07-29
        • 1970-01-01
        • 2021-08-18
        相关资源
        最近更新 更多