question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser bundle contains NodeJS code that throws "Uncaught TypeError: Cannot read properties of undefined (reading 'split')"

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.3.8

Node.js version

16.14.0

MongoDB server version

4.2.19

Description

When bundling up mongoose for the browser this code is included from the file dist/browser.umd.js:

e.nodeMajorVersion=parseInt(t.versions.node.split(".")[0],10);

It throws this error in Chrome:

Uncaught TypeError: Cannot read properties of undefined (reading 'split')

My guess is that the code line above was never supposed to end up in the browser bundle because it is server-side node code.

Steps to Reproduce

See the browser.umd.js file in the dist folder of mongoose.

Expected Behavior

The browser.umd.js contains only browser-compatible code.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
rowlanchcommented, Sep 13, 2022

I am also experiencing this issue with mongoose 6.5.5 on node 16.17.

I can reproduce with a simplified example:

❯ cat package.json
{
  "name": "mongoose-error",
  "version": "1.0.0",
  "dependencies": {
    "mongoose": "~6.5.5"
  }
}
❯ npm i

added 28 packages, and audited 29 packages in 820ms

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
❯ grep -r "nodeMajor" node_modules/mongoose/*
node_modules/mongoose/dist/browser.umd.js:e.noop=function(){},e.errorToPOJO=function(t){if(!(t instanceof Error))throw new Error("`error` must be `instanceof Error`.");var e,r={},o=n(Object.getOwnPropertyNames(t));try{for(o.s();!(e=o.n()).done;){var i=e.value;r[i]=t[i]}}catch(t){o.e(t)}finally{o.f()}return r},e.nodeMajorVersion=parseInt(t.versions.node.split(".")[0],10)}).call(this,r(10))},function(t,e,r){"use strict";(function(t){

Downgrading to mongoose 6.5.2 removes the nodeMajorVersion reference.

0reactions
clathey123commented, Nov 1, 2022

Has this issue been resolved??? If so, how do I implement the latest release of mongoose?

Thank you! Cheryl

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read Property 'split' of Undefined in JS
The "Cannot read property 'split' of undefined" error occurs when trying to call the `split()` method on a variable that stores an `undefined`...
Read more >
Uncaught TypeError: Cannot read property 'split' of undefined
If og_date contains the date, it's probably a string, so og_date.value is undefined. Simply use og_date.split('-') instead of og_date.value.
Read more >
Cannot Read Property 'split' of Undefined - freeCodeCamp
it will throw the TypeError: Cannot read property 'split' of undefined error. ... It then returns an array containing the substrings:
Read more >
cannot read properties of undefined (reading 'split') mongoose
Automattic/mongooseBrowser bundle contains NodeJS code that throws "Uncaught TypeError: Cannot read properties of undefined (reading 'split')"#11943.
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found