parcel icon indicating copy to clipboard operation
parcel copied to clipboard

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

Open mccahan opened this issue 2 years ago • 3 comments

🐛 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!

mccahan avatar Jul 28 '22 17:07 mccahan

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.

AGawrys avatar Jul 28 '22 19:07 AGawrys

Whoop, sorry @AGawrys, repo is public now!

mccahan avatar Jul 28 '22 19:07 mccahan

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.

sznowicki avatar Sep 15 '22 14:09 sznowicki

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"
   }
 }

mischnic avatar Mar 16 '23 21:03 mischnic

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.

github-actions[bot] avatar Mar 25 '24 12:03 github-actions[bot]