导入mongoose仅中断执行。

huangapple go评论86阅读模式
英文:

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(&quot;mongoose&quot;)

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 &#39;?&#39;
    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.&lt;anonymous&gt; (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"

huangapple
  • 本文由 发表于 2023年7月31日 21:13:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76803998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定