mongoose: QueryCursor.js is throwing an error on line 144: "TypeError: Cannot assign to read only property 'map' of object '#'"

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

QueryCursor.js is throwing an error on line 144:

QueryCursor.prototype.map = function(fn) {

Trying to assign to read only property ‘map’ of object

TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>'
    at Object.<anonymous> (/Users/balonsom/Documents/repos/dungeon-master/node_modules/mongoose/lib/cursor/QueryCursor.js:144:27)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/balonsom/Documents/repos/dungeon-master/node_modules/mongoose/lib/query.js:12:21)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)

If the current behavior is a bug, please provide the steps to reproduce.

This bug only arose when I upgrade Node.js to v17.5.0. I don’t think I can easily provide a script to replicate.

What is the expected behavior?

QueryCursor.js should not throw an error.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.

Mongoose: 6.2.1 Node.js: 17.5.0 MongoDB: 4.4

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 25

Commits related to this issue

Most upvoted comments

Same happening to mongoose 5.7.7 MongoDB 4.4.12 Node 17.5.0

Temp fix: change your package.json engines line to this:

"engines": { "node": ">=12.0.0 <17.5.0" },

Opened ticket in nodejs bugtracker regarding this

https://github.com/nodejs/node/issues/41926

thank you guys

my old docker file is this -

image

When i changed this -

image

NOW WORKING FINE

Thanks @abeledovictor

"node": ">=14.0.0 <17.5.0" worked for me

You can change the node version to v14 and the error gets fixed for now.

Latest version 17.6.0 of node with the fix (https://github.com/nodejs/node/pull/41931) is out : https://github.com/nodejs/node/releases/tag/v17.6.0 Tested it and the error is gone.

Not available in docker yet as :latest image still points to 1.17.5 but it should be available very soon. Most users should use the :lts docker tag though as it points to the latest long term support stable release (currently 16.14.0) which never had this error.

This is not a kubernetes specific issue. Kubernetes is a docker orchestrator. So you have to modify your dockerfile to use a working node base image.

Also I would recommend to you to not use odd major versions of node, as they are bleeding edge. Best practice is to use LTS-versions for production, to specifically avoid such issues, and those are node versions with even major-version (12, 14, 16…).

If you use node:latest in your dockerfile, than you are using node 17.5, according to dockerhub. And thats why you have issues.

Best practice for node docker images is to pinpoint exact versions down to patch-version. E.g. use 16.14.0-alpine3.15 instead of 16-alpine. Thus also avoiding caching an old node 16 base image in docker and then wondering why you building on a different machine breaks.