Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX BUG: Uncaught Error: Mismatched anonymous define() module fix #1506

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sgeleon
Copy link

@sgeleon sgeleon commented May 7, 2024

Hi.

Sometimes we will get this error: "Uncaught Error: Mismatched anonymous define() module fix".

According documentation Magento 2, we must collect all js scripts in directory JS.

web: Optional directory that contains static files organized into the following subdirectories:

css/source: Contains a theme's less configuration files that invoke mixins for global elements from the [UI library](https://developer.adobe.com/commerce/frontend-core/guide/css/ui-library/), and the theme.less file that overrides the default variables values.
css/source/lib: Contains view files that override the [UI library](https://developer.adobe.com/commerce/frontend-core/guide/css/ui-library/) files stored in lib/web/css/source/lib.
fonts: The folder to place the different fonts for your theme.
images: Static images folder.
js: **The folder for your JavaScript files.**

Magento 2 use the pattern 'js' in the path of url for marking it in the requireJS which don't know scructure of Magento 2.

This requiest fix it.

@cammonro
Copy link
Contributor

cammonro commented May 7, 2024

Thank you @sgeleon for your contribution!

Would you be able to please provide the steps to reproduce the issue that this PR addresses?

@sgeleon
Copy link
Author

sgeleon commented May 8, 2024

Hi @cammonro.

I cann't give you the steps to reproduce it because this bug is arriving only in some customization of Magento 2, don't default. Magento 2 use some plugins of RequireJS for getting correct the URL from Magento path for example:

Algolia_AlgoliaSearch/js/autocomplete. -> {domain}/static/version1715092518/frontend/{Module_name}/default/en_AU/Algolia_AlgoliaSearch/js/autocomplete.js

@atIOCrON
Copy link

Hi @cammonro
Could we please have an update on when you will merge this fix?

@cammonro
Copy link
Contributor

@sgeleon thanks for the added context. It's helpful to know which kind of customizations can trigger this issue so if you encounter further discoveries down the road please feel free to update this PR with details.

Meanwhile, this code has been organized "as is" for a long time but what you've requested is a reasonable ask! We'll look into this further to assess the impact.

@atIOCrON This kind of thing would not go into a patch release but an upcoming minor version update which we are currently working on. I can't promise when but if we don't identify any obstacles to its inclusion we'll aim to add it to one of these upcoming releases.

The primary concern is the potential impact to customers who have overridden these file paths for their own customizations which we'll need to call out. In the meantime, you can run a diff on this PR to apply the change in your own Magento instance.

We're a small team so please know that we appreciate your effort here to help us improve the quality of our Magento extension!

cc @rachel-trott

@atIOCrON
Copy link

Thanks, @cammonro , we're looking forward to the minor release.

To see how this bug is reproduced on our staging site, you may check the Algolia support ticket # 619388. We'd prefer not to post our staging URL publicly on GitHub.

@cammonro
Copy link
Contributor

@atIOCrON Understood! Thanks for the head's up there. We'll be sure to give that another look when we evaluate this.

@ethmelly
Copy link

Hello , i tried applying the diff and i still encounter same error
Uncaught Error: Mismatched anonymous define() module: function(e){"use strict";var t="2.13.0";function o(e)
The error seems to be related to the
<script async="" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/search-insights.min.js"></script>
which is added dynamically by algoliaBundle.

We don't have any customization to the module or any mixins.

Why is this loaded from cdn if search-insights is present locally ? is there a way to fix this ?

@cammonro
Copy link
Contributor

@ethmelly Typically that library should not be loaded dynamically unless explicitly enabled. Can you please open a support ticket where you can provide steps to reproduce and environment details?

@ethmelly
Copy link

ethmelly commented May 29, 2024

@cammonro The problem is from this commit 1464 . In this release the reference to search-insights was added in algoliaBundle. I switched back to version 3.12.1 and is fine now.
Maybe the bundle was built wrong ?

Later edit:
I installed back 3.13.2 and switched algoliaBundle.min to the old version from 3.12.1 and the script is not loaded dynamically anymore. If you check the diff from the commit above you can see there was no reference to
"https://cdn.jsdelivr.net/npm/search-insights@".concat(pa, "/dist/search-insights.min.js" . I'm guessing when the bundle was built this was included by mistake since as i said search-insights is present locally in /internals/search-insights.js

@cammonro
Copy link
Contributor

@ethmelly This is great feedback. Dynamic insights loading was introduced in v4.55 of InstantSearch so the previous version in the earlier bundle (v4.41) would not have the added references. But if it's loading from a CDN in addition to loading from the local static cache like you're seeing then that's a problem.

We'll want to understand what's going on here so we'll be sure to take a look at this. However, if you can please share the steps to reproduce that would be very helpful, such as where the behavior manifests, any configurations etc.

@ethmelly
Copy link

@cammonro the error is happening in production environment , on some page loads ( not every single one ) , most likely due to race condition on how the scripts are loaded on category pages with Instant Search Results Page enabled , replace categories page Yes.

If you need we can open support ticket and maybe provide you with access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants