Modern browser downloading legacy bundle and dynamic import fails

From time to time, we are getting this type of error in montiAPM

Error: Cannot find module '/node_modules/react-youtube/dist/YouTube.js'
    at meteor://💻app/packages/modules-runtime.js:232:11
    at makeMissingError (meteor://💻app/packages/modules-runtime.js:335:14)
    at fileEvaluate (meteor://💻app/packages/modules-runtime.js:248:13)
    at require (meteor://💻app/packages/modules.js:346:21)
    at link (meteor://💻app/packages/dynamic-import.js:215:9)
    at getNamespace (meteor://💻app/packages/dynamic-import.js:50:11)
    at apply (meteor://💻app/packages/meteor.js:1343:21)
clientArch: web.browser.legacy

But the client is a modern browser:

Browser: Chrome (Blink) - Mac OS - 10.15.7

Therefore, the file cannot be found because dynamic import is looking for the file within the modern build, but it was looking for a legacy file; therefore, the dynamic import fails.

Any recommendation on what we should be checking? This happens maybe once or twice a week

Hey David, are you working with local packages?

I found this bug in Meteor in 2019 where it was misclassifying some modules, maybe you got another edge case like this Fixes `cannot find module` error when using dynamic imports in massive projects by filipenevola · Pull Request #10730 · meteor/meteor · GitHub

1 Like

Hi @filipenevola. We have forked packages. I will take a look at the thread and give feedback here. Thanks

to be clear: I don’t think this is the same issue but my fix could help you to find places to debug :slight_smile:

The biggest challenge we are facing is that we cannot replicate this issue locally or in production. It is also not being experienced by all users. We also know that the specific user who encountered this recovered by closing the tab and opening the app on another browser tab.

I will investigate the case of multiple layers of nested imports