microsoft / TypeScript-Node-Starter

A reference example for TypeScript and Node with a detailed README describing how to use the two together.
MIT License
11.31k stars 2.77k forks source link

Error(s) on update dependencies #340

Closed mozgbrasil closed 3 years ago

mozgbrasil commented 3 years ago

Good morning my friends

About updating libraries

When using the ncu

https://www.npmjs.com/package/npm-check-updates

I updated the dependencies of the "package.json" file

{
  "name": "@mozg/express-labs-ts",
  "version": "0.1.0",
  "description": "A starting point for Node.js express apps with TypeScript",
  "repository": {
    "type": "git",
    "url": "https://github.com/Microsoft/TypeScript-Node-Starter"
  },
  "author": "Bowden Kelly",
  "license": "MIT",
  "scripts": {
    "build-sass": "sass src/public/css/main.scss dist/public/css/main.css",
    "build-ts": "tsc",
    "build": "yarn run build-sass && yarn run build-ts && yarn run lint && yarn run copy-static-assets",
    "copy-static-assets": "ts-node copyStaticAssets.ts",
    "debug": "yarn run build && yarn run watch-debug",
    "lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
    "serve-debug": "nodemon --inspect dist/server.js",
    "serve": "node dist/server.js",
    "start": "yarn run serve",
    "test": "jest --forceExit --coverage --verbose",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"yarn run watch-sass\" \"yarn run watch-ts\" \"yarn run serve-debug\"",
    "watch-node": "nodemon dist/server.js",
    "watch-sass": "sass --watch src/public/css/main.scss dist/public/css/main.css",
    "watch-test": "yarn run test -- --watchAll",
    "watch-ts": "tsc -w",
    "watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"yarn run watch-sass\" \"yarn run watch-ts\" \"yarn run watch-node\""
  },
  "dependencies": {
    "async": "3.2.1",
    "bcrypt-nodejs": "0.0.3",
    "bluebird": "3.7.2",
    "body-parser": "1.19.0",
    "compression": "1.7.4",
    "connect-mongo": "4.4.1",
    "dotenv": "10.0.0",
    "errorhandler": "1.5.1",
    "express": "4.17.1",
    "express-flash": "0.0.2",
    "express-session": "1.17.2",
    "express-validator": "6.12.1",
    "fbgraph": "1.4.4",
    "lodash": "4.17.21",
    "lusca": "1.7.0",
    "mongoose": "5.13.7",
    "nodemailer": "6.6.3",
    "passport": "0.4.1",
    "passport-facebook": "3.0.0",
    "passport-local": "1.0.0",
    "pug": "3.0.2",
    "winston": "3.3.3"
  },
  "devDependencies": {
    "@types/async": "3.2.7",
    "@types/bcrypt-nodejs": "0.0.31",
    "@types/bluebird": "3.5.36",
    "@types/body-parser": "1.19.1",
    "@types/chai": "4.2.21",
    "@types/compression": "1.7.1",
    "@types/concurrently": "6.2.1",
    "@types/cookie-parser": "^1.4.2",
    "@types/errorhandler": "1.5.0",
    "@types/eslint": "7.28.0",
    "@types/express": "4.17.13",
    "@types/express-flash": "0.0.2",
    "@types/express-session": "1.17.4",
    "@types/jest": "27.0.1",
    "@types/jquery": "3.5.6",
    "@types/jsonwebtoken": "^8.5.4",
    "@types/lodash": "4.14.172",
    "@types/lusca": "1.7.1",
    "@types/mongodb": "4.0.6",
    "@types/node": "16.6.1",
    "@types/nodemailer": "6.4.4",
    "@types/passport": "1.0.7",
    "@types/passport-facebook": "2.1.11",
    "@types/passport-local": "1.0.34",
    "@types/pug": "2.0.5",
    "@types/request": "2.48.7",
    "@types/request-promise": "4.1.48",
    "@types/shelljs": "0.8.9",
    "@types/supertest": "2.0.11",
    "@types/winston": "2.4.4",
    "@typescript-eslint/eslint-plugin": "4.29.2",
    "@typescript-eslint/parser": "4.29.2",
    "chai": "4.3.4",
    "concurrently": "6.2.1",
    "eslint": "7.32.0",
    "jest": "27.0.6",
    "nodemon": "2.0.12",
    "sass": "1.37.5",
    "shelljs": "0.8.4",
    "supertest": "6.1.5",
    "ts-jest": "27.0.4",
    "ts-node": "10.2.0",
    "typescript": "4.3.5"
  }
}

But error is being returned

Debugger attached.
$ tsc
Debugger attached.
../../node_modules/connect-mongo/build/main/lib/MongoStore.d.ts:2:22 - error TS2724: '"mongodb"' has no exported member named 'CommonOptions'. Did you mean 'CommandOptions'?

2 import { Collection, CommonOptions, MongoClient, MongoClientOptions } from 'mongodb';
                       ~~~~~~~~~~~~~

src/app.ts:71:9 - error TS2322: Type '{ autoReconnect: true; }' is not assignable to type 'MongoClientOptions'.
  Object literal may only specify known properties, and 'autoReconnect' does not exist in type 'MongoClientOptions'.

71         autoReconnect: true,
           ~~~~~~~~~~~~~~~~~~~

  ../../node_modules/connect-mongo/build/main/lib/MongoStore.d.ts:17:5
    17     mongoOptions?: MongoClientOptions;
           ~~~~~~~~~~~~
    The expected type comes from property 'mongoOptions' which is declared here on type 'ConnectMongoOptions'

Found 2 errors.

Waiting for the debugger to disconnect...
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Thank you in advance if you can help

peterblazejewicz commented 3 years ago

There were two signifiant changes recently in mongoose and mongodb, that are not reflected here yet. Both were rewritten and migrated to native TS version, so the code here - and also in 'connect-mongo' could be not in sync with a versions you're trying to use, directly. That is without minor updates here and there. For example, connection option autoReconnect is no longer even defined in current mongodb options, hence the error: https://github.com/mongodb/node-mongodb-native/blob/4ecaa37f72040ed8ace6eebc861b43ee9cb32a99/src/index.ts

mozgbrasil commented 3 years ago

Hello

Thank you so much for interacting

In the future I try again to use the updated dependencies.