Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs: Cannot find module 'passport'

I am missing something fairly basic at the beginning of my exploration into Node.js. I am trying to build a little app using passportjs authentication.

I have the following line in my app.ts:

import passport = require("passport");

and the following im my package.json:

{
    "name": "ftct",
    "version": "0.0.0",
    "description": "ftct",
    "main": "app.js",
    "author":
    {
        "name": "Mark.Norgate",
        "email": ""
    },
    "dependencies":
    {
        "express": "3.4.4",
        "jade": "*",
        "passport": "^0.3.2",
        "stylus": "*"
    }
}

However, Visual Studio 2015 complains:

Build: Cannot find module 'passport'.

What am I missing? I have read a little of the documentation for passportjs but nothing so far that indicates what the problem might be.

like image 553
serlingpa Avatar asked Nov 19 '15 15:11

serlingpa


4 Answers

Adding a new module to your package.json won't actually include the dependency in the repository. You'll need to either run npm install after adding dependencies to package.json, or you can install packages using something like npm install <package name>. In this case, you'd want npm install passport.

npm install will download the source from npm and put it into the ./node_modules directory.

npm install documentation

like image 185
Matt Avatar answered Nov 11 '22 08:11

Matt


Change:

import passport = require("passport");

to:

var passport = require("passport");
like image 45
Jared Dykstra Avatar answered Nov 11 '22 09:11

Jared Dykstra


I had a similar issue where passport was installed and properly saved in package.json but was still getting an error.

My issue was that within package.json there were the lines

"engines": {
    "node": ">=6.9.1"
  },

I compared my package.json to other examples online and then removed that line and it worked.

like image 1
ickydime Avatar answered Nov 11 '22 07:11

ickydime


Remove node_modules, remove package-lock.json, then run npm install and then run npm install --save passport.

like image 1
Yigit Alparslan Avatar answered Nov 11 '22 07:11

Yigit Alparslan