parcel-bundler / parcel

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

Tagged template literals across files only return the first instance of the literal after build #7989

Open Alamantus opened 2 years ago

Alamantus commented 2 years ago

🐛 bug report

When I run parcel build on my project (at last commit using parcel) and open the resulting html file in a browser, the rendered file returns a duplicated but mangled global view nested within the global view instead of the target view.

Using parcel serve does not produce this error, so there must be something going wrong with the build process.

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

🤔 Expected Behavior

It should display the html of the target view nested within the global view:

image

😯 Current Behavior

It is re-rendering the global view nested within itself, but with inconsistently mangled text and link errors:

image

💁 Possible Solution

Not sure what's causing the problem, but it looks like whatever minification process is being used is storing the value returned by views/global.js and re-using it everywhere the html template literal tag is being used?

Disabling my custom transformers did not change the result for me, so I don't think they are related.

🔦 Context

I'm trying to produce a single HTML file with the transpiled JS inside of a script tag. It works correctly when using npm start but not when I use npm run build. I also have an npm test script that starts a node server in case the browser doesn't like running HTML files from the file system.

💻 Code Sample

https://github.com/Alamantus/FeatherWiki (last commit using parcel)

To reproduce:

  1. clone the repo & npm install
  2. run npm start & visit localhost:1234 to see how it's supposed to behave
  3. run npm test & visit localhost:3000 to see what's going wrong

🌍 Your Environment

Software Version(s)
Parcel ^2.4.1
Node v16.14.2
npm 8.5.0
Operating System Windows 10 Pro version 21H1 build 19043.1645

Also occurs in MacOS and when using either Firefox or Chromium.

mischnic commented 2 years ago

I haven't checked the output yet but this sounds very similar to https://github.com/parcel-bundler/parcel/issues/7101

Alamantus commented 2 years ago

@mischnic

I haven't checked the output yet but this sounds very similar to #7101

That's what I had found before I submitted the issue, but I was able to build my project without an error so it seemed worth a new submission (though it's worth mentioning that adding not ios_saf < 13 to the browserlist as suggested in recent comments was necessary to get it to build). But it does sounds like a similar (if not the same) cause!

Alamantus commented 1 year ago

I'm not using Parcel for this project anymore, but I will say that it's irritating seeing so many issues marked as stale or auto-closed across GitHub just because time has passed. Just because nobody has commented on something doesn't mean the problem has magically gone away, and these GitHub actions that pretend like they're not bugs anymore drive me insane.