Search code examples
node.jsmongodbdateherokuwebpack

I am getting this error TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>' 2022-02-19T12:38:49.101286+00:00 app[web.1]:


I am trying to deploy my node.js app for weeks but I am not able to deploy it, Please can someone please help me to deploy this, I have done everything, but still Heroku says application error. Please help to solve this issue, I am getting these error in my Heroku logs

Starting process with command `node index.js`
2022-02-19T12:38:49.101275+00:00 app[web.1]: /app/node_modules/mongoose/lib/cursor/QueryCursor.js:144
2022-02-19T12:38:49.101284+00:00 app[web.1]: QueryCursor.prototype.map = function(fn) {
2022-02-19T12:38:49.101285+00:00 app[web.1]: ^
2022-02-19T12:38:49.101285+00:00 app[web.1]:
2022-02-19T12:38:49.101286+00:00 app[web.1]: TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>'
2022-02-19T12:38:49.101286+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:144:27)
2022-02-19T12:38:49.101286+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1097:14)
2022-02-19T12:38:49.101286+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
2022-02-19T12:38:49.101287+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:975:32)
2022-02-19T12:38:49.101287+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-02-19T12:38:49.101287+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:999:19)
2022-02-19T12:38:49.101288+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-02-19T12:38:49.101288+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/query.js:12:21)
2022-02-19T12:38:49.101288+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1097:14)
2022-02-19T12:38:49.101288+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
2022-02-19T12:38:49.101292+00:00 app[web.1]:
2022-02-19T12:38:49.101292+00:00 app[web.1]: Node.js v17.5.0
2022-02-19T12:38:49.222099+00:00 heroku[web.1]: Process exited with status 1
2022-02-19T12:38:49.270154+00:00 heroku[web.1]: State changed from starting to crashed
2022-02-19T12:38:49.273378+00:00 heroku[web.1]: State changed from crashed to starting
2022-02-19T12:38:52.851143+00:00 heroku[web.1]: Starting process with command `node index.js`
2022-02-19T12:38:54.692822+00:00 app[web.1]: /app/node_modules/mongoose/lib/cursor/QueryCursor.js:144
2022-02-19T12:38:54.692840+00:00 app[web.1]: QueryCursor.prototype.map = function(fn) {
2022-02-19T12:38:54.692841+00:00 app[web.1]: ^
2022-02-19T12:38:54.692841+00:00 app[web.1]:
2022-02-19T12:38:54.692841+00:00 app[web.1]: TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>'
2022-02-19T12:38:54.692842+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/cursor/QueryCursor.js:144:27)
2022-02-19T12:38:54.692842+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1097:14)
2022-02-19T12:38:54.692842+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
2022-02-19T12:38:54.692843+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:975:32)
2022-02-19T12:38:54.692843+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-02-19T12:38:54.692843+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:999:19)
2022-02-19T12:38:54.692844+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-02-19T12:38:54.692844+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/query.js:12:21)
2022-02-19T12:38:54.692844+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1097:14)
2022-02-19T12:38:54.692844+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
2022-02-19T12:38:54.692845+00:00 app[web.1]:
2022-02-19T12:38:54.692845+00:00 app[web.1]: Node.js v17.5.0
2022-02-19T12:38:54.845812+00:00 heroku[web.1]: Process exited with status 1
2022-02-19T12:38:55.309883+00:00 heroku[web.1]: State changed from starting to crashed
2022-02-19T12:38:56.377269+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=i-book-backend.herokuapp.com request_id=bc0cecd2-3197-43c3-9b15-6adbfa62943a fwd-6adbfa62943a fwd="150.129.159.93" dyno= connect= service= status=503 bytes= protocol=https
2022-02-19T12:38:57.014602+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=i-book-backend.herokuapp.com request_id=26338aa4-0e9b-41d4-b2b4-9cf32b-41d4-b2b4-9cf32ab946fa fwd="150.129.159.93" dyno= connect= service= status=503 bytes= protocol=https
2022-02-19T12:40:27.841439+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=i-book-backend.herokuapp.com request_id=9ecc5d99-e1fe-47cc-815c-ffde34a9568b fwd-ffde34a9568b fwd="150.129.159.93" dyno= connect= service= status=503 bytes= protocol=https
2022-02-19T12:40:28.357238+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=i-book-backend.herokuapp.com request_id=2d493654-9b7c-40f7-9e35-073c3c-40f7-9e35-073c3b950e51 fwd="150.129.159.93" dyno= connect= service= status=503 bytes= protocol=https

Here is my index.js file

const connectToMongo = () => { require('./db') };
const express = require('express')
var cors = require('cors')
connectToMongo();
const dotenv = require('dotenv')
dotenv.config();

const app = express()
// app.use(cors())
app.use(cors({
  origin: "*",
}));
const port = process.env.PORT || 5000
https://runkit.com/

app.use(express.json())


app.use('/api/auth/', require('./routes/auth'))
app.use('/api/notes', require('./routes/notes'))



app.listen(port, () => {
  console.log(`i-book backend app listening at http://${port}`)
})

Please let me know, if I should more details from my side.


Solution

  • According to this issue in GitHub, it's a problem with node latest release v17.5.0 and mongoose that hasn't been addressed yet.

    in order to temporary fix this issue change Nodejs engine version in the package.json file like this :

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

    Note: you need to deploy your app again in order to reinstall Nodejs.