Home  >  Q&A  >  body text

Importing mongoose only causes execution to break

The line of code causing the problem is importing mongoose into the code const mongoose = require("mongoose")

and it will show the following 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: 意外的标记 '?'
    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 will not appear

Without any interaction with mongodb or mongoose, I have no idea what's going on

I tried reinstalling mongodb on my computer and removed the mongoose import, nothing else interacted with mongoose I expected it to be like a normal import

P粉135799949P粉135799949398 days ago576

reply all(1)I'll reply

  • P粉513316221

    P粉5133162212023-09-18 00:21:17

    I solved this problem The problem was ultimately because the mongoose version was newer than my node version, which caused me to use features that my version did not have and errors occurred. mongoose version: "^7.4.1" node version: v12.22.1

    Now I'm using: mongoose version: "^5.9.20"

    reply
    0
  • Cancelreply