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

arr[i].toUpperCase() if not a function #435

Closed
joker-777 opened this issue Oct 13, 2021 · 1 comment · Fixed by #456
Closed

arr[i].toUpperCase() if not a function #435

joker-777 opened this issue Oct 13, 2021 · 1 comment · Fixed by #456
Labels
bug Something isn't working

Comments

@joker-777
Copy link

joker-777 commented Oct 13, 2021

Hi, we see in our javascript tracking system (Rollbar) that some users experience this error with this code in the amplitude-js/amplitude.umd.js.

          enumerize = function (arr) {
              var enums = {};
              for (var i in arr) {
                  enums[arr[i].toUpperCase()] = arr[i];
              }    
              return enums;
          },   
TypeError: e[n].toUpperCase is not a function

File "node_modules/amplitude-js/amplitude.umd.js" line 2872 col 24 in enumerize
enums[arr[i].toUpperCase()] = arr[i];

File "node_modules/amplitude-js/amplitude.umd.js" line 3333 col 26 in [anonymous]
UAParser.BROWSER = enumerize([NAME, VERSION, MAJOR]);

File "node_modules/amplitude-js/amplitude.umd.js" line 2809 col 5 in [anonymous]
(function (window, undefined$1) {

File "node_modules/amplitude-js/amplitude.umd.js" line 1902 col 8 in createCommonjsModule
}, fn(module, module.exports), module.exports;

File "node_modules/amplitude-js/amplitude.umd.js" line 2796 col 18 in [anonymous]
var uaParser = createCommonjsModule(function (module, exports) {

File "node_modules/amplitude-js/amplitude.umd.js" line 4 col 83 in [anonymous]
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typ...

File <no filename> line 4 col 83 in Object.120

File "webpack/bootstrap" line 68 col 22 in __webpack_require__
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

File <no filename> line 7 col 23 in Module.279

File "webpack/bootstrap" line 68 col 22 in __webpack_require__
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

Do you have any idea why?

Environment

  • JS SDK Version: 8.8.0
  • Installation Method: import amplitude from "amplitude-js"
  • Browser and Version: Chrome 94
@joker-777 joker-777 added the bug Something isn't working label Oct 13, 2021
@GalvinGao
Copy link

GalvinGao commented Oct 22, 2021

We have used a patch in our app to mitigate this issue, however I found that in the affecting package, @amplitude/ua-parser-js, a PR has already been filed 17 days ago but received no responses from the team. The patch is described below and can be applied using patch-package in case someone needs it to mitigate this issue:

diff --git a/node_modules/amplitude-js/amplitude.umd.js b/node_modules/amplitude-js/amplitude.umd.js
--- a/node_modules/amplitude-js/amplitude.umd.js
+++ b/node_modules/amplitude-js/amplitude.umd.js
@@ -2817,7 +2817,9 @@
           enumerize = function (arr) {
               var enums = {};
               for (var i in arr) {
-                  enums[arr[i].toUpperCase()] = arr[i];
+                  if (arr.hasOwnProperty(i)) {
+                    enums[arr[i].toUpperCase()] = arr[i];
+                  }
               }
               return enums;
           },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants