【问题标题】: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]:我收到此错误 TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>' 2022-02-19T12:38:49.101286+00:00 app[web.1]:
【发布时间】:2022-04-29 02:26:22
【问题描述】:

我正在尝试部署我的 node.js 应用程序数周,但我无法部署它,请有人帮我部署它,我已经完成了所有工作,但 Heroku 仍然显示应用程序错误。 请帮助解决这个问题,我的 Heroku 日志中出现这些错误

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

这是我的 index.js 文件

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}`)
})

如果我需要更多详细信息,请告诉我。

【问题讨论】:

    标签: node.js mongodb date heroku webpack


    【解决方案1】:

    根据 GitHub 中的这个issue,这是 node 最新版本 v17.5.0 和 mongoose 尚未解决的问题。

    为了临时解决此问题,请更改 package.json 文件中的 Nodejs 引擎版本,如下所示:

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

    注意:您需要重新部署您的应用才能重新安装 Nodejs。

    【讨论】:

    • 我的node版本已经改成14.0.0了,要不要改成12.0.0?
    • 我建议您使用我提到的相同代码,因为当我将它添加到我的项目节点时,已安装 17.4.0 并且问题已修复。目前尚不清楚哪个版本的节点将满足您的项目需求,并且找到任何一个都没有意义,因此使用较低版本也可能在运行时出错。
    • 好的,我试试看
    • 需要安装node 16.14.0 LTS版本,安装后我的错误解决了
    【解决方案2】:

    如果您使用的是内置 fetch 等实验性功能,Node 17.6.0 修复了这个问题

    【讨论】:

      猜你喜欢
      • 2023-02-22
      • 2016-02-22
      • 2020-09-20
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 2021-04-10
      • 2019-04-05
      相关资源
      最近更新 更多