Bug with passport-strategy: TypeError: Class extends value undefined is not a constructor or null
See original GitHub issueBug 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
or change the behavior of how Typescript treats CommonJS modules by default
Some references:
See @Epochi answer