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

Closed
wants to merge 2 commits into from

Conversation

sgeleon
Copy link
Contributor

@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
Contributor 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/search-insights@2.13.0/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

@cammonro
Copy link
Contributor

cammonro commented Jun 3, 2024

@ethmelly Please do open a support ticket if you can. That would actually be useful to help us troubleshoot this further.

@FlorianFauvelNolaConsulting

Hi @sgeleon,

You forgot to change the css path in the algolia_search_handle layout xml which result to a 404 in frontend.

@sgeleon
Copy link
Contributor Author

sgeleon commented Jun 21, 2024

Hi @FlorianFauvelNolaConsulting.

You forgot to change the css path in the algolia_search_handle layout xml which result to a 404 in frontend.

Thank you. I updated the branch.

@damcou damcou changed the base branch from develop to bugfix/MAGE-926/js-reorg July 3, 2024 15:22
@damcou damcou changed the base branch from bugfix/MAGE-926/js-reorg to develop July 3, 2024 15:22
damcou added a commit that referenced this pull request Jul 4, 2024
damcou added a commit that referenced this pull request Jul 4, 2024
@damcou damcou mentioned this pull request Jul 9, 2024
damcou added a commit that referenced this pull request Jul 9, 2024
damcou added a commit that referenced this pull request Jul 9, 2024
damcou added a commit that referenced this pull request Jul 9, 2024
@cammonro
Copy link
Contributor

Asset reorg slated for 3.14.0 release: #1563

damcou added a commit that referenced this pull request Jul 10, 2024
* MAGE-926: port changes from PR #1506

* MAGE-926: port changes from PR #1506

* MAGE-926: fix logo path

* MAGE-926: move css file into appropriate folder

* MAGE-926: move js templates from internals
@cammonro
Copy link
Contributor

This code change request has been implemented in the recently released version 3.14.0 of our extension and the separate issue related to dynamic insights loading via CDN is being addressed on an internal customer ticket. Closing this PR.

@cammonro cammonro closed this Aug 19, 2024
@manish85sixty
Copy link

Is there any update on dynamic insights loading via CDN as It's impacting our customer as well?

@ethmelly
Copy link

Hello @manish85sixty

The issue was fixed for me when I did the following. Suggested from algolia support team when reaching them directly via support.

"Events → Settings → Automatic events collection enabled and if the issue is resolved when you disable it? " <- in algolia dashboard for the application where you have the issue.

Most likely this is the only fix atm for magento until further notice from them.

@cammonro
Copy link
Contributor

@manish85sixty Yes - @ethmelly is correct (thanks for weighing in!). Make sure you do not enable "Automatic events collection" in the Algolia dashboard, as doing so circumvents Magento's own RequireJS dependency loading and creates that error condition:

image

Instead enable events collection through the Magento extension itself under Stores → Configuration → Algolia Search → Click & Conversion Analytics.

image

We will be updating our documentation to make this clearer. If this ever changes in the future we'll be sure to announce it through our release notes.

@manish85sixty
Copy link

Thankyou @ethmelly and @cammonro.

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

Successfully merging this pull request may close these issues.

6 participants