question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with passport-strategy: TypeError: Class extends value undefined is not a constructor or null

See original GitHub issue

Bug Report

passport-activedirectory throw an Exception on application start.

Current behavior

When Nest.js application starts, throw the following exception:

TypeError: Class extends value undefined is not a constructor or null
    at Object.PassportStrategy 
    at Object.<anonymous> 
    at Module._compile (module.js:652:30)
    at Module.m._compile
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] 
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)

This is my code:

AuthModule

import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { AdStrategy } from "./strategies/ad.strategy";
import {PassportModule} from '@nestjs/passport';

@Module({
  imports: [PassportModule],
  controllers: [AuthController],
  providers: [AuthService, AdStrategy]
})

export class AuthModule {

}

AdStrategy (strategies/ad.strategy.ts)

import {Strategy} from "passport-activedirectory";
import {AuthService} from "../auth.service";
import {PassportStrategy} from '@nestjs/passport';
import {Injectable} from "@nestjs/common";

@Injectable()
export class AdStrategy extends PassportStrategy(Strategy, 'activedirectory') {

    constructor(private readonly authService: AuthService) {
        super({
            integrated: false,
            ldap: {
                url: 'ldap://my.domain.com',
                baseDN: 'DC=my,DC=domain,DC=com',
                username: 'readuser@my.domain.com',
                password: 'readuserspassword'
            }
        });
    }

    async validate(profile, ad): Promise<any> {
         // TODO
         const user = this.authService.validateUser(username, password);
        if (!user) {
            throw new UnauthorizedException();
        }
        return user;
    }
}

Expected behavior

I expect the application run without exception.

Environment

Nest version: 6.0.0

For Tooling issues:

  • Node version: v8.11.2
  • Platform: Mac

Repository

https://github.com/djfabrix/nest-passport-ad-test

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
Epochicommented, Nov 26, 2019

this is probably because passport-activedirectory is a CommonJS module and TypeScript expects ES6 modules.

You can either change how the module is imported into the strategy file

// strategies/ad.strategy.ts
import * as Strategy from "passport-activedirectory";

or change the behavior of how Typescript treats CommonJS modules by default

// tsconfig.json
{
 "compilerOptions": {
    "esModuleInterop": true,
    ...
 },
  ...
}


// strategies/ad.strategy.ts
import Strategy from "passport-activedirectory";

Some references:

0reactions
kamilmysliwieccommented, Nov 28, 2019

See @Epochi answer

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Class extends value undefined is not a constructor ...
I got this error that "Sequelize TypeError: Class extends value undefined is not a constructor or null, NodeJS" and solved it using that....
Read more >
class extends value undefined is not a constructor or null nestjs
Without extending it works very well, but in this case it is crashing. Test suite failed to run TypeError: Class extends value undefined...
Read more >
TypeError: Class extends value undefined is not a constructor ...
js:163 class Request extends OriginalRequest { ^ TypeError: Class extends value undefined is not a constructor or null at createNodePonyfill (/ ...
Read more >
TypeError: Class extends value undefined is not a ... - Drupal
TypeError : Class extends value undefined is not a constructor or null. Closed (fixed). Project: Drupal State.
Read more >
CommandOperation "Class extends value undefined is not a ...
Type: Bug ... Fix Version/s: None. Component/s: None. Labels: None ... TypeError: Class extends value undefined is not a constructor or null.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found