parcel: Regression: `Uncaught error: Cannot find module`

I’m sorry for submitting such a general report without a small repro case. But this bug has already cost me a lot of time, and I’m very much at a loss for how to deal with it. I thought I’d file what I could, though.

🐛 bug report

Check out the following:

Run:

npm install
make clean dev

Then visit http://localhost:3333/twisty/twisty-player.html and check the browser console.

See https://www.youtube.com/watch?v=PXkfFrLHS6o for an example of a successful build (beginning of video) and 8:32 for a failure.

To avoid the behaviour:

npm install parcel@2.0.0-nightly.481 # no bug
rm -rf ./node_modules/ ; npm install; make clean dev

To cause the behaviour (sometimes):

npm install parcel@2.0.0-nightly.485 # bug
rm -rf ./node_modules/ ; npm install; make clean dev

(Parcel nightly versions 482/483/484 do not exist.)

🤔 Expected Behavior

No error. The page loads, shows a Rubik’s Cube, and a table for some options.

😯 Current Behavior

Sometimes (the vast majority of the time, maybe 90%?) after running npm install from scratch, the following error appears:

Uncaught Error: Cannot file module '2du48'.

This seems to correspond to ./dom/viewers/Twisty3DCanvas. It seems clear that there’s an issue with the loading graph somehow related to this file, starting in parcel@2.0.0-nightly.485.

See https://garron.net/temp/cubing-js-parcel-2021-01-18.zip for the state of the cache folder when this occurs.

Sometimes after running npm install (maybe 10% of the time?), however, there is no error. As far as I can tell, the error doesn’t occur until the next time I delete node_modules and run npm install from scratch, which rolls the dice again.

💁 Possible Solution

No idea, I’m sorry. I’ve tried to dig into stack traces, but something is going wrong deep inside Parcel’s module loading code and I can’t debug it from inside my code.

I can’t figure out how to map Parcel nightlies to Git commits, but correlating the version dates at https://www.npmjs.com/package/parcel with https://github.com/parcel-bundler/parcel/commits/v2?after=bdc45e49437b986934d3b1b0d8f6a4ecc292a2aa+34&branch=v2 suggests that this regression was introduced in this range:

https://github.com/parcel-bundler/parcel/compare/a4cf3e958ea1136b4829eb93615fba5328213471...f89e5ef87fcb58e6131475b5218f188cc231a1d9

🔦 Context

I was trying to debug a Parcel bug that is breaking our production build. I tried to update Parcel to the latest nightly 2.0.0-nightly.539 and was able to observe a bug in dev. After spending over 24 hours, I finally concluded that our production bug is not the same as the bug that was caused by upgrading to 2.0.0-nightly.539. I’m going to downgrade for now in order to debug the other issue, but I’ve filed this issue to document the one that happened due to the upgrade.

💻 Code Sample

See above.

🌍 Your Environment

Software Version(s)
Parcel parcel@2.0.0-nightly.485 and above (I bisected. 481 and lower do not exhibit this issue, 482/483/484 do not exist, 485 and above do exhibit the issue).)
Node v15.4.0
npm/Yarn 6.14.11
Operating System macOS 10.15.7 as well as Big Sur (I can repro this issue on two different computers)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 30 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I am having the same issue with Cannot find module xxx, which corresponds to "@parcel/transformer-js/src/esmodule-helpers.js"

parcel 2.0.0 npm 8.1.0 node 16.13.0 macOS 11.6 Safari 15.0 (16612.1.29.41.4, 16612)

I have the same problem.

Uncaught Error: Cannot find module '622nD'
    at a (index.cad93178.js:1:578)
    at Object.<anonymous> (index.ts:2:1)
    at a (index.cad93178.js:1:534)
    at runtime-c3897e95e15efd7e.js:1:58

Changing this in my entry index.html fixed it for me. Weird that I had no issues on 2.0.1.

diff --git a/app/public/index.html b/app/public/index.html
index 2b0e175da..1efda18df 100644
--- a/app/public/index.html
+++ b/app/public/index.html
@@ -47,6 +47,8 @@
       To begin the development, run `npm start` or `yarn start`.
       To create a production bundle, use `npm run build` or `yarn build`.
     -->
-    <script src="../src/index.tsx" type="module"></script>
+    <script type="module">
+      import "../src/index.tsx";
+    </script>
   </body>
 </html>

I just updated to Parcel 2.0.1 and still having the same issue. Is this a configuration option problem in our stack or is this a bug in Parcel?

I believe my issue is related (if not duplicate). I’m happy to say I made a repro repo and also I found a workaround for all affected: bundler-experimental seems to be free of this bug.

Issue with repro repo: https://github.com/parcel-bundler/parcel/issues/8480

Workaround .parcelrc:

{
  "extends": "@parcel/config-default",
  "bundler": "@parcel/bundler-experimental"
}

Also hitting this on 2.3.2. Some level of complexity in the bundle graph seems to trigger it. The missing bundle is being generated, but the underlying js file is not being loaded client side. Tried fixing by removing scope hoisting and source mapping, but no luck.

Only occurs in build, not watch, since it’s related to code splitting.

Changing this in my entry index.html fixed it for me. Weird that I had no issues on 2.0.1.

diff --git a/app/public/index.html b/app/public/index.html
index 2b0e175da..1efda18df 100644
--- a/app/public/index.html
+++ b/app/public/index.html
@@ -47,6 +47,8 @@
       To begin the development, run `npm start` or `yarn start`.
       To create a production bundle, use `npm run build` or `yarn build`.
     -->
-    <script src="../src/index.tsx" type="module"></script>
+    <script type="module">
+      import "../src/index.tsx";
+    </script>
   </body>
 </html>

@Aloento In my case I am using bootstrap.

If I do:

<body>
    <script type="module" src="../js/scripts/home.js"></script>
    <script type="module" src="../js/vendors/bootstrap.js"></script>
</body>

in this order, I get this strange error. But, if I change the imports order to:

<body>
    <script type="module" src="../js/vendors/bootstrap.js"></script>
    <script type="module" src="../js/scripts/home.js"></script>
</body>

(bootstrap first), the error is gone!

I have an even simpler repro: https://github.com/yume-chan/parcel-repro-5683

a.js and b.js each imports a different image file, so they are completely unrelated. When I include a.js before b.js in index.html, it works, then change the order, cannot find module.

Uncaught Error: Cannot find module 'ciiiV'
    at newRequire (index.a28fffaf.js:61:19)
    at newRequire (index.a28fffaf.js:45:18)
    at localRequire (index.a28fffaf.js:84:35)
    at Object.8FjLI../a.png (runtime-1f074fef905954b1.js:473:2)
    at newRequire (index.a28fffaf.js:71:24)
    at index.a28fffaf.js:122:5
    at index.a28fffaf.js:145:3

It’s related to build cache. If I clean the build cache, I can get the reversed behavior.

I’m also experiencing the same issue and updating parcel to 2.0.1 didn’t solve it.

parcel: 2.0.0-nightly.776

I’ve bisected the commits, this is a regression of https://github.com/parcel-bundler/parcel/pull/5200.

Happens consistently for me with the minimal reproduction: https://github.com/mischnic/parcel-issue-5683

For dist/a.html, the script tags for the shared bundles are added in the wrong order.

I can’t figure out how to map Parcel nightlies to Git commits

The hash is appended to the version field in the published tarball, you can see that for example here: https://unpkg.com/browse/parcel@2.0.0-nightly.447/package.json