mongoose: Browser bundle contains NodeJS code that throws "Uncaught TypeError: Cannot read properties of undefined (reading 'split')"
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- test: add test for gh-11943 — committed to maciasello/mongoose by maciasello 2 years ago
- test: add test for gh-11943 — committed to maciasello/mongoose by maciasello 2 years ago
- test: add test for gh-11943 — committed to maciasello/mongoose by maciasello 2 years ago
I am also experiencing this issue with mongoose 6.5.5 on node 16.17.
I can reproduce with a simplified example:
Downgrading to mongoose 6.5.2 removes the nodeMajorVersion reference.