From d9e99483fdb5248ffbdc3cc0a8e64c827045d6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Thu, 20 Jun 2024 09:45:32 +0100 Subject: [PATCH] chore(docs): add a troubleshooting section Share learnings from working with `require.js` which is used in certain Magento setups. --- README.md | 8 ++++++++ src/queue.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a1753c0..52905ac 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,14 @@ Finally, in case you are using banners and want to have further control on the a ``` +# Troubleshooting + +## I see `Uncaught Error: Mismatched anonymous define() module` in the browser console + +You are most likely running into issues with how the library is loaded. This is a common issue with RequireJS and other AMD loaders. The library is not AMD compatible, so you need to load it as a global script. + +Another approach is to use the ESM version of the library, which you can either import directly should you import the library as part of your distribution; or use the published version called `ts.mjs`: `https://unpkg.com/@topsort/analytics.js@2.3.1/dist/ts.mjs`. + # E2E tests Execute `npm run test:e2e`, at the end it will show you the url you need to visit to test the library. diff --git a/src/queue.ts b/src/queue.ts index 32e95dc..5afa2cc 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -1,4 +1,4 @@ -import { Store, MemoryStore, LocalStorageStore } from "./store"; +import { type Store, MemoryStore, LocalStorageStore } from "./store"; const STORAGE_TEST_KEY = "ts-t"; const STORAGE_KEY = "ts-q"; @@ -51,7 +51,7 @@ function expBackoff(startTime: number, retries: number): number { * Probes the different store implementations looking for one that works in the current browser. * * To do so, it checks {@link LocalStorageStore} is actually functional by adding a dummy object and - * checking the retrived result is the same. + * checking the retrieved result is the same. * * Note: there's nothing special about the id, but it need to be ideally a length one string, in * order to minimize the JS library size.