英文:
importing mongoose just breaks execution
问题
引起问题的代码行只是将mongoose导入到代码中
const mongoose = require("mongoose")
并且它会出现错误:
this.options = options ?? {};
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\libor\OneDrive\Escritorio\todo\dev\Aplay\proyectos\mustang-oneclic\node_modules\mongodb\lib\admin.js:4:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
如果我删除require(
行,错误就不会出现
没有与mongodb或mongoose互动的内容,我不知道发生了什么
我尝试在我的电脑上重新安装mongodb并删除mongoose的导入,没有其他与mongoose互动的内容
我希望它像正常导入一样。
英文:
the line that causes the problem is jus importing mongoose into the code
const mongoose = require("mongoose")
and it drops the error:
C:\Users\libor\OneDrive\Escritorio\todo\dev\Aplay\proyectos\mustang-oneclic\node_modules\mongodb\lib\operations\add_user.js:16
this.options = options ?? {};
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\libor\OneDrive\Escritorio\todo\dev\Aplay\proyectos\mustang-oneclic\node_modules\mongodb\lib\admin.js:4:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
if I remove the require(
line the error doesn't apear
there is nothing interacting with mongodb nor mongoose, I have no clue what is happening
I tried installing mongodb in my pc again and removing the mongoose inport, nothing else is interacting with mongoose
I expected it to import like normal
答案1
得分: 0
我已修复它
最终发现是 mongoose 版本超过了我的 node 版本,因此导致了错误,因为我使用了我的版本没有的功能
mongoose:"^7.4.1"
node: v12.22.1
现在我正在使用:
mongoose:"^5.9.20"
英文:
I fixed it
It ended up being that the mongoose version was ahead of my node version, thus causing errors for using features my version doesn't have
mongoose:"^7.4.1"
node: v12.22.1
now I'm using:
mongoose:"^5.9.20"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论