Definitelytyped: @types/mongoose 5.0.1 installs incorrect @types/mongodb as dependency

Created on 8 Feb 2018  路  13Comments  路  Source: DefinitelyTyped/DefinitelyTyped

Package installs legacy @types/mongodb as dependency which results in

node_modules/@types/mongoose/index.d.ts(2392,29): error TS2694: Namespace '"...node_modules/@types/mongodb/index"' has no exported member 'ChangeStreamOptions'.


node_modules/@types/mongoose/index.d.ts(2392,77): error TS2694: Namespace '"...node_modules/@types/mongodb/index"' has no exported member 'ChangeStream'.

Installed @types/mongodb has in its package.json

    "name": "@types/mongodb",
    "version": "2.2.16",

while current one is 3.0.5. The package compiles just fine via @types/mongodb, v3.0.5

  • Authors: @simonxca @horiuchi @sindrenm @lukasz-zak @Alorel

Most helpful comment

@lustoykov @types/mongodb has a "*" dependency, so it should not be forcing you to use an older version. Maybe you have a lockfile that's keeping it at an old version?

All 13 comments

+1

But no error when use watch mode ???? (-w)

@andy-ms How can we specify a specific @types package version as a dependency? I tried creating a package.json, but the test script fails saying I can't specify @types packages there.

{
    "dependencies": {
        "@types/mongodb": ">=3.0.0"
    }
}
art@art-linux-opt8:~/Documents/DefinitelyTyped$ npm test

> [email protected] test /home/art/Documents/DefinitelyTyped
> node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed

Clean data
Clean logs
Clean output
# Typing Publish Report Summary
Started at Fri, 09 Feb 2018 14:20:34 GMT
Found 4069 typings folders in /home/art/Documents/DefinitelyTyped/types
Error: In /home/art/Documents/DefinitelyTyped/types/mongoose/package.json: Don't use a 'package.json' for @types dependencies.
    at checkPackageJsonDependencies (/home/art/Documents/DefinitelyTyped/node_modules/types-publisher/src/lib/definition-parser.ts:166:10)
    at /home/art/Documents/DefinitelyTyped/node_modules/types-publisher/src/lib/definition-parser.ts:110:34
    at Generator.next (<anonymous>)
    at fulfilled (/home/art/Documents/DefinitelyTyped/node_modules/types-publisher/bin/lib/definition-parser.js:4:58)
    at <anonymous>
Error: Parsing failed.
    at fail (/home/art/Documents/DefinitelyTyped/node_modules/types-publisher/src/util/util.ts:320:11)
    at ChildProcess.child.on (/home/art/Documents/DefinitelyTyped/node_modules/types-publisher/src/util/util.ts:308:6)
    at ChildProcess.emit (events.js:160:13)
    at finish (internal/child_process.js:775:14)
    at process._tickCallback (internal/process/next_tick.js:150:11)
npm ERR! Test failed.  See above for more details.
art@art-linux-opt8:~/Documents/DefinitelyTyped$

@lustoykov as a temporary workaround, try explicitly adding a @types/mongodb dependency in your project with the version set to >=3.0.0.

@types/mongoose depends on "@types/mongodob": "*", which should be the latest version if you didn't specify anything else. It's possible to use path mapping to specify a dependency on a specific older version of a package, but for the latest the dependency will always be "*". This can sometimes cause problems (see #23257), but right now you'll just have to specify a higher mongodb version in your own package.json (or specify none at all and depend on the default being the latest).

as a temporary workaround, try explicitly adding a @types/mongodb dependency in your project with the version set to >=3.0.0.

@Alorel, unfortunately that doesn't work since the global @types/mongodb is being detected and @types/mongoose installs its local version of @types/mongodb directly into its own node_modules folder.

@lustoykov @types/mongodb has a "*" dependency, so it should not be forcing you to use an older version. Maybe you have a lockfile that's keeping it at an old version?

@andy-ms - spot on, that was the problem!

Thanks everybody for the help, I'm closing the issue.

Having the exact same issue with @types/mongoose v5.0.10.

node_modules/@types/mongoose/index.d.ts(2492,29): error TS2694: Namespace '".../node_modules/@types/connect-mongo/node_modules/@types/mongodb/index"' has no exported member 'ChangeStreamOptions'.
node_modules/@types/mongoose/index.d.ts(2492,77): error TS2694: Namespace '".../node_modules/@types/connect-mongo/node_modules/@types/mongodb/index"' has no exported member 'ChangeStream'.

I'm not sure what's the deal here, I'm using node v8.10.0 and npm v5.6.0.
I tried deleting my package-lock.json and reinstalling all the packages, also reinstalled my @types/mongoose package without success.

I don't really understand why mongoose is looking for mongodb's types in connect-mongo's types whereas I also installed @types/mongodb.

Any help will be appreciated, thanks !

@Anthony59273
try install npm install --save-dev @types/mongoose@^4.7.8

@serveryang That made it! Thanks a lot!

@serveryang Downgrade @types/mongoose is not an option for me, is any other workaround ?. Is this something related to https://github.com/jdesboeufs/connect-mongo/pull/278 ?

My issue was that I had an old version in my yarn.lock, try deleting it and install newest @types/mongoose again.

I temporarily solved the conflicting versions of the @types/mongodb between @types/mongoose and @types/connect-mongo, by uninstalling @types/connect-mongo: npm uninstall -D @types/connect-mongo and declaring the "connect-mongo" module as "any" in the custom definitions file (e.g. src/custom.d.ts). IMO, this workaround is ok for now, as I use "connect-mongo" in one place only (when I setup the session store).

Same with latest @types of mongoose but it is enoug to add @types/mongodb manually

$ npm i -D @types/[email protected]
Was this page helpful?
0 / 5 - 0 ratings