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

Mismatched anonymous define() module error when pixel is loaded #11

Open
drabikowy opened this issue Dec 27, 2024 · 0 comments
Open

Mismatched anonymous define() module error when pixel is loaded #11

drabikowy opened this issue Dec 27, 2024 · 0 comments

Comments

@drabikowy
Copy link

drabikowy commented Dec 27, 2024

Hello!
I have an issue with implementing outbrain pixel tag in my shop using GTM Tag Template.

The problem is that the shop is based on Magento with its requireJS implementation (amd modules architecture), and loading outbrain pixel ends up with this error (that breaks functionalities in the shop)

Uncaught Error: Mismatched anonymous define() module: ()=>(()=>{"use strict";var e,t,n={},o={};function r(e){var t=o[e];if(void 0!==t)return t.exports;var i=o[e]={exports:{}};return n[e](i,i.exports,r),i.exports}r.m=n,r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce(((t,n)=>(r.f[n](e,t),t)),[])),r.u=e=>e+".js",r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="conversion-pixel-tag:",r.l=(n,o,i,a)=>{if(e[n])e[n].push(o);else{var s,c;if(void 0!==i)for(var u=document.getElementsByTagName("script"),p=0;p<u.length;p++){var l=u[p];if(l.getAttribute("src")==n||l.getAttribute("data-webpack")==t+i){s=l;break}}s||(c=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,r.nc&&s.setAttribute("nonce",r.nc),s.setAttribute("data-webpack",t+i),s.src=n),e[n]=[o];var d=(t,o)=>{s.onerror=s.onload=null,clearTimeout(f);var r=e[n];if(delete e[n],s.parentNode&&s.parentNode.removeChild(s),r&&r.forEach((e=>e(o))),t)return t(o)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),c&&document.head.appendChild(s)}},r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.g.importScripts&&(e=r.g.location+"");var t=r.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),(()=>{var e={805:0};r.f.j=(t,n)=>{var o=r.o(e,t)?e[t]:void 0;if(0!==o)if(o)n.push(o[2]);else{var i=new Promise(((n,r)=>o=e[t]=[n,r]));n.push(o[2]=i);var a=r.p+r.u(t),s=new Error;r.l(a,(n=>{if(r.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var i=n&&("load"===n.type?"missing":n.type),a=n&&n.target&&n.target.src;s.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",s.name="ChunkLoadError",s.type=i,s.request=a,o[1](s)}}),"chunk-"+t,t)}};var t=(t,n)=>{var o,i,[a,s,c]=n,u=0;if(a.some((t=>0!==e[t]))){for(o in s)r.o(s,o)&&(r.m[o]=s[o]);c&&c(r)}for(t&&t(n);u<a.length;u++)i=a[u],r.o(e,i)&&e[i]&&e[i][0](),e[i]=0},n=this.webpackChunkconversion_pixel_tag=this.webpackChunkconversion_pixel_tag||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))})();var i={};function a(e){return Array.isArray(e)}function s(e){return Object.keys(e).map((function(t){return"".concat(t,"=").concat(encodeURIComponent(e[t]))})).join("&")}r.r(i);var c=function(){},u=function(e,t,n){var o=e[t];e[t]=function(){var e=o.apply(this,arguments);return n.apply(this,arguments),e}},p=function(e,t,n){(window.postMessage||c)({action:"log",type:e,message:t,name:n},"*")};function l(e){if(e)return"string"==typeof e?e.replace(" ","").split(","):a(e)?e:void 0}var d,f,h,v="has_concent_event",g=[1,3,4];!function(e){e.Default="all",e.EuZone1="euZone1",e.EuZone2="euZone2"}(d||(d={})),function(e){e.Product="product"}(f||(f={})),function(e){e.Log="log",e.Warning="warning",e.Info="info",e.Error="error"}(h||(h={}));var m="PAGE_VIEW",y="dicbo",w="dicbo_id",b="dicbo_fetch",C="ob_cvr_pixel_domain",k="obamplify",_="obtp",E=new(function(){function e(){this.validCurrencies=["USD","CAD","EUR","GBP","ILS","AUD","MXN","BRL","SEK","SGD","RUB","NZD","INR","JPY","PHP","CHF"],this.validNameRegX=new RegExp("^[A-Za-z0-9]+[A-Za-z0-9- ]*$"),this.validNumber=new RegExp("^[0-9]+[.0-9]*$"),this.validNameLength=100}return e.prototype.validate=function(e){return e.content&&e.content.id,e.orderValue&&!e.currency?(p(h.Warning,"Order value reported but no currency is declared",e.name),!1):e.currency&&-1===this.validCurrencies.indexOf(e.currency)?(p(h.Warning,"Currency not recognized",e.name),!1):e.orderValue&&!this.validNumber.test(e.orderValue)?(p(h.Warning,"Order value can only be a positive number",e.name),!1):e.name===m||this.validNameRegX.test(e.name)?!(e.name!==m&&e.name.length>this.validNameLength&&(p(h.Warning,"Event name length cannot exceed 100 characters",e.name),1)):(p(h.Warning,"Event Name invalid",e.name),!1)},e}()),O=new(function(){function e(){}return e.prototype.getParamFromUrl=function(e){var t=this.getLocation();t.indexOf("#")>-1&&(t=t.substring(0,t.indexOf("#")));for(var n=(t.split("?")[1]||"").split(/&/),o=0;o<n.length;o++)if(this.startsWith(n[o],e))return this.getParamValue(n[o]);return""},e.prototype.getLocation=function(){var e="";try{e=window.top.location.href||document.location.href}catch(t){e=document.location.href}return e||""},e.prototype.startsWith=function(e,t){return 0===e.indexOf(t+"=")},e.prototype.getParamValue=function(e){return e.split("=")[1].split("#")[0]},e}()),S=function(e,t,n){if(n||2===argumenhttps://requirejs.org/docs/errors.html#mismatch
    at makeError (a45ae667ff81022883b55bba0d454edb.min.js:17:53)
    at intakeDefines (a45ae667ff81022883b55bba0d454edb.min.js:84:132)
    at a45ae667ff81022883b55bba0d454edb.min.js:107:45

Issue can be simply solved by using a named module instead of anonymous declaration.

In this script which is injected by the template:
https://amplify.outbrain.com/cp/obtp.js

To make error disappear, there shall be some kind of a name defined where "define" is being called:

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports...

for example

...
define("outbrain-pixel-or-any-other-unique-name",[],t):"object"==typeof exports?exports
...

Could you please check this issue?
The fix shall be quite easy and safe to implement.
Otherwise, do you have any suggestion how can we avoid this issue?

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

No branches or pull requests

1 participant