parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.5k stars 2.27k forks source link

Bundling with html entry stopped working in 2.8.0 #8635

Closed KillerCodeMonkey closed 1 year ago

KillerCodeMonkey commented 1 year ago

I just updated parcel from 2.7.0 to 2.8.0 and my app target is not recognized

🐛 bug report

🎛 Configuration (.babelrc, package.json, cli command)

{
  "app": "./dist/app/index.html",
  "targets": {
    "app": {
      "engines": {
        "browsers": "> 0.25%"
      },
      "context": "browser",
      "isLibrary": false,
      "distDir": "./dist/app"
    },
  }
}

🤔 Expected Behavior

just bundles and is working as before

😯 Current Behavior

Error:

🚨 Parcel encountered errors
@parcel/namer-default: Target "app" declares an output file path of "dist/app/index.html" which does not match the compiled bundle type "js".
[/package.json:41:10](http://localhost:1234/__parcel_launch_editor?file=%2Fpackage.json%3A41%3A10)
> 41 |   "app": "./dist/app/index.html",
>    |          ^^^^^^^^^^^^^^^^^^^^^^^ Did you mean "dist/app/index.js"?
  42 |   "targets": {
  43 |     "app": {

    Try changing the file extension of "app" in package.json.

💁 Possible Solution

/

🔦 Context

Just want to update my deps

🌍 Your Environment

Software Version(s)
Parcel 2.8.0
Node 16.18.0
npm/Yarn 8.5
Operating System Ubuntu 22.0.4
devongovett commented 1 year ago

Could you please provide a reproduction?

KillerCodeMonkey commented 1 year ago

I can try it tomorrow. In general it is an html page loading an react app.

Devon Govett @.***> schrieb am Mi., 16. Nov. 2022, 16:57:

Could you please provide a reproduction?

— Reply to this email directly, view it on GitHub https://github.com/parcel-bundler/parcel/issues/8635#issuecomment-1317244682, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARI4YH2BMYMOCPB7ILEJ73WIUAAJANCNFSM6AAAAAASB5ZHME . You are receiving this because you authored the thread.Message ID: @.***>

KillerCodeMonkey commented 1 year ago

@devongovett when i remove "app": "./dist/app/index.html", it is working.

KillerCodeMonkey commented 1 year ago

if it is not needed to link the output files that way, you can close the issue. Thank you

mischnic commented 1 year ago

What are you passing as the entry point? A JS file or an HTML file? Because your config plus parcel build src/index.html works for me.

KillerCodeMonkey commented 1 year ago

i setup a new clean project an it is working there as well.

the entry is the .html page for serve and build.

the strange thing: when i change just out of curiosity index.html to index.js like recommended in the error. it fails as well recommending to use .html

KillerCodeMonkey commented 1 year ago

and another funny thing: i have other target for electron-renderer defined the same way, but the target is electron-renderer and it is working. let me check a little bit further, if i can find a the root cause

mischnic commented 1 year ago

So what the error is telling you is that the filetype you specified as the entry (so in parcel build src/index.js) doesn't match the type in the package.json target (so "app": "./dist/app/index.html"). Does that explain what you're seeing?

My question now is whether these two filetypes match up in your situation (how it should be) but you're still getting that error. If you only get this error if the filetypes don't match, then this is working as intended.

If you need both cases to work (separately), you can do this to "disable" some target where the type is wrong:

{
  "app": "./dist/app/index.html",
  "app-js": "./dist/index.js",
  "targets": {
    "app": {},
    "app-js": {},
  },
  "scripts": {
    "build": "parcel build src/index.html --target app"
    "build-js": "parcel build src/index.js --target app-js"
  }
}
KillerCodeMonkey commented 1 year ago

got it.

"app": "dist/app/index.html",
"electron-renderer": "./dist/renderer/index.html"

i have two targets which are consuming and producing html files. if i add the electron-renderer it is failing for the app

KillerCodeMonkey commented 1 year ago

seems like thats not it... so here is my full list of targets in the package.json

  "app": "dist/app/index.html",
  "electron-renderer": "./dist/launcher/renderer/index.html",
  "electron-main": "./dist/launcher/main/main.js",
  "electron-preload": "./dist/launcher/preload/preload.js",
  "targets": {
    "app": {
      "engines": {
        "browsers": "> 0.25%"
      },
      "context": "browser",
      "isLibrary": false,
      "distDir": "./dist/app"
    },
    "electron-preload": {
      "context": "electron-main",
      "distDir": "./dist/launcher/preload"
    },
    "electron-main": {
      "context": "electron-main",
      "distDir": "./dist/launcher/main"
    },
    "electron-renderer": {
      "context": "browser",
      "distDir": "./dist/launcher/renderer",
      "isLibrary": false,
      "publicUrl": ".",
      "engines": {
        "browsers": "> 0.25%"
      }
    }
  }

when i execute "parcel serve src/app/index.html --target app --dist-dir dist/app --port 1234 --no-cache"

it is not working with the error above. if i remove "app": "dist/app/index.html", everything works.

mischnic commented 1 year ago

That appears to be working for me: https://github.com/mischnic/parcel-issue-8635

KillerCodeMonkey commented 1 year ago

i think we can close it. since it occurs in a huge project. i have not the time to investigate further and it is working on a newly created project.

sorry for the delay.