parcel-bundler / parcel

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

Two HTML files using different order of identical JS includes results in "cannot find module" error #8342

Closed mccahan closed 7 months ago

mccahan commented 2 years ago

🐛 bug report

When using two linked HTML files with two JS files that utilize the same includes, if the order of the <script> tags in the HTML is not the same, you get a "Cannot find module" console error, e.g.:

Screenshot 2022-07-28 at 11 35 16@2x

I put together a minimal reproducible test case here: https://github.com/mccahan/parcel-order-bug-demo . In that demo: indexa.html includes a.js, then b.js and functions correctly indexb.html includes b.js, then a.js and throws an error

Both JS files import the same library (using GSAP here but I don't think it matters), but are otherwise completely independent of one another.

If I change the HTML files to have the same order (either a,b or b, a, it doesn't matter) the error goes away and everything functions as intended.

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

See my reproducible test case here: https://github.com/mccahan/parcel-order-bug-demo

package.json:

{
  "name": "parcel-bug",
  "version": "1.0.0",
  "license": "MIT",
  "dependencies": {
    "parcel": "^2.6.2"
  }
}

🤔 Expected Behavior

The order of these independent JS files shouldn't matter; they include the same external library but they don't interfere with each other at all.

😯 Current Behavior

The second processed HTML file (in my reproducible test case, indexb.html, shows a Cannot find module error:

Screenshot 2022-07-28 at 11 43 42@2x

💁 Possible Solution

🔦 Context

We have a website where we use GSAP in multiple scripts on multiple pages, with one common shared script and then independent scripts for each page to add additional page-specific functionality. We were hitting this error message on one page that happened to have the main.js file after the the page-specific scripts for that page instead of the first script on the page, so it was failing.

The error message was pretty useless and I couldn't find anything in the manual about it, so it was really a matter of trial-and-error to figure out what the issue was. Ideally it either handles this situation correctly, or has some kind of useful error message to indicate what's happening

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.6.2
Node v18.4.0
npm/Yarn 1.22.17
Operating System macOS Monterey 12.4, Apple M1 chip

Thank you!

AGawrys commented 2 years ago

I'm not able to access the repro link, is this still an issue for you ? I'd be happy to take a look if yes.

mccahan commented 2 years ago

Whoop, sorry @AGawrys, repo is public now!

sznowicki commented 2 years ago

I have similar problem but with a much bigger mono repo. Have tons of those "cannot find module", only in production build. Failed to make a repro repo yet though.

mischnic commented 1 year ago

Still broken with the new bundler:

diff --git package.json package.json
index 3ad483e..6941f3a 100644
--- package.json
+++ package.json
@@ -3,6 +3,7 @@
   "version": "1.0.0",
   "license": "MIT",
   "dependencies": {
-    "parcel": "^2.6.2"
+    "gsap": "^3.11.4",
+    "parcel": "2.8.3"
   }
 }
github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.