Router.use TypeError: Unable to read the 'use' property from undefined

I am new to node.js, experts, please help. I am preparing code for user synchronization based on node.js + AWS Cognito + Facebook Login. I tried an example from this.

Each step runs smoothly, as long as the "facebook sing with with passport" section

var express = require('express');
var router = express.Router();
var passport = require('passport');
...
router.use(passport.initialize());
...

After adding this part in the example, I run "npm start", the following error appeared:

C:\workspace\nodejs\CognitoExample\routes\index.js:35
router.use(passport.initialize());
      ^

TypeError: Cannot read property 'use' of undefined

What does “Unable to read property” mean? How to solve a problem? Thanks in advance.


After a few experts help here, I can solve the problem:

  • reinstall express

Yesterday I used the npm install -g express-generator @ 3 command, so my global configuration expresses version 3. First I uninstall and install express.

npm uninstall -g express-generator@3
npm uninstall -g express
npm install -g express
npm install -g express-generator
  • node_modules

1 , , express 3.x , , ,

+4
3

, , 4.x Express. Express 4.x 3.x. , express.Router(). , ( ), Express.

+5

& es6 .

:

import * as passport from "passport";

import passport from "passport";

.:

0

I had a similar problem. I put the code after app.use(express.static...)and it worked.

-1
source

Source: https://habr.com/ru/post/1611883/


All Articles