P
P
Pavlo Ponomarenko2018-09-11 03:16:58
JavaScript
Pavlo Ponomarenko, 2018-09-11 03:16:58

What if npm @types dependencies create a conflict in TypeScript?

As soon as I do npm i, I immediately get a bunch of errors that start like this:

node_modules/@types/connect-mongo/node_modules/@types/mongoose/index.d.ts:77:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: NativeBuffer, NativeDate, NativeError, Mongoose, CastError, ConnectionBase, Connection, ValidationError, Error, VirtualType, Schema, MongooseDocument, Subdocument, Array, DocumentArray, Buffer, ObjectIdConstructor, Decimal128, Embedded, Query, DocumentQuery, mquery, Aggregate, SchemaType

77 declare module "mongoose" {
   ~~~~~~~

  node_modules/@types/mongoose/index.d.ts:48:1
    48 declare module "mongoose" {
       ~~~~~~~
    Conflicts are in this file.

node_modules/@types/connect-mongo/node_modules/@types/mongoose/index.d.ts:703:48 - error TS2314: Generic type 'HookAsyncCallback<T>' requires 1 type argument(s).

703     pre(method: string, parallel: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): this;
                                                   ~~~~~~~~~~~~~~~~~

node_modules/@types/connect-mongo/node_modules/@types/mongoose/index.d.ts:704:29 - error TS2314: Generic type 'HookSyncCallback<T>' requires 1 type argument(s).

704     pre(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): this;
                                ~~~~~~~~~~~~~~~~

node_modules/@types/connect-mongo/node_modules/@types/mongoose/index.d.ts:766:13 - error TS2428: All declarations of 'HookSyncCallback' must have identical type parameters.

766   interface HookSyncCallback {
                ~~~~~~~~~~~~~~~~

node_modules/@types/connect-mongo/node_modules/@types/mongoose/index.d.ts:770:13 - error TS2428: All declarations of 'HookAsyncCallback' must have identical type parameters.

770   interface HookAsyncCallback {
                ~~~~~~~~~~~~~~~~~

node_modules/@types/mongoose/index.d.ts:48:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: NativeBuffer, NativeDate, NativeError, Mongoose, CastError, ConnectionBase, Connection, ValidationError, Error, VirtualType, Schema, MongooseDocument, Subdocument, Array, DocumentArray, Buffer, ObjectIdConstructor, Decimal128, Embedded, Query, DocumentQuery, mquery, Aggregate, SchemaType

48 declare module "mongoose" {
   ~~~~~~~

Should I delete the directory
/node_modules/@types/connect-mongo/node_modules/@types
how everything works great. How to solve this problem correctly?
npm version is 6.4.1, node version is v8.11.4.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
L2jLiga, 2018-10-01
@L2jLiga

It is enough to make sure that the l ranges of versions @types/mongoosein @types/connect-mongoand in your project are compatible
. Alternatively, specify in your package json
"@types/mongoose": "*"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question