parcel-bundler / parcel

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

Parcel v2 fails silently #4322

Open lucasterra opened 4 years ago

lucasterra commented 4 years ago

🐛 bug report

I run parcel and it says everything went fine, when actually it did not. Nothing shows up on http://localhost:1234.

$ parcel index.html --open
ℹī¸ Server running at http://localhost:1234
✨ Built in 73ms

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

I have created a repro repo here: https://github.com/lucasterra/parcel-dynamic-import-repro/tree/v2

🤔 Expected Behavior

It should report what went wrong, so I can fix it.

đŸ˜¯ Current Behavior

Nothing happens, it just says everything is fine.

DeMoorJasper commented 4 years ago

Looks like an invalid parcel config, we probably need better error handling for it

lucasterra commented 4 years ago

Yes, it is probably wrong or outdated. I copy/pasted it from here: https://github.com/parcel-bundler/parcel#parcelrc

Maybe I'm missing a package that needs to be installed?

DeMoorJasper commented 4 years ago

You should probably install all plugins you list in parcelrc otherwise it'll auto-install.

Besides that it's also invalid, for example:

"*.{png,jpg,jpeg,svg,...}": ["@parcel/optimizer-imagemin"]

Should be:

"*.{png,jpg,jpeg,svg}": ["@parcel/optimizer-imagemin"]

and the imagemin plugin does not even exist.

The docs also really need to be updated and organised properly... but that's a different topic we're already planning to start working on asap

mischnic commented 4 years ago

How did you come up with that configuration?

  1. As already pointed out, the *.{png,jpg,jpeg,svg,...} is invalid, but that's is actually not causing a problem here.
  2. You wrote "*.js": ["@parcel/transformer-babel"], but this will only run babel on the files and not actually bundle them because @parcel/transformer-js is what registers the imports.
  3. Same goes for @parcel/transformer-html (e.g. process <a>, <script>, ...)

Pretending that a imagemin and vue plugin existed, this would be what you want:

{
  "extends": ["@parcel/config-default"],
  "transformers": {
    "*.vue": ["@parcel/transformer-vue"]
  },
  "optimizers": {
    "*.{png,jpg,jpeg,svg}": ["@parcel/optimizer-imagemin"]
  }
}

The "silent fail" happens because you "explicitly" told Parcel in the config to not process script tags in html.

DeMoorJasper commented 4 years ago

Ow I actually thought parcel froze, but after re-reading it actually builds as expected. The config is copy-pasted from the readme.

We might still want to do better error reporting on this though, although besides the invalid *.{png,jpg,jpeg,svg,...} and non-existing plugins I'm not sure how we could improve it without people who do really want to overwrite everything getting a warning like did you mean to exclude @parcel/transformer-js? It will disable import gathering and resolution

We definitely do need to put a valid and useful config example in the future docs though...