During the development of my project using Nest.js, I came across an error that I couldn't find a solution for. The issue arises when I try to export a function from one file and import it into a controller. Even though the function is exported correctly in the code snippet below:
import { AuthGuard } from '@nestjs/passport';
export class AdminGuard extends AuthGuard ('admin'){
constructor(){
super();
}
}
To export this:
export * from './admin-jwt.strategy'`
Here's how it is used in the controller:
import { Controller, Get,UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { JwtGuard,AdminGuard } from 'src/auth/guard';
import { DynamicRole } from 'src/auth/decorator';
@UseGuards(AdminGuard,DynamicRole)
@DynamicRole('superadmin', 'support')
@Controller('user')
export class UserController {
constructor(private userservice:UserService){}
@Get('me')
getme(){
return this.userservice.getme();
}
}
The console shows this error message. I've tried restarting the server, checking the tsconfig.json
, and inspecting the dist folder for any errors, but to no avail.
In the tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
I also attempted to switch from commonjs
to ECMAScript 6, but encountered another error stating that a built-in module was not found, as shown in this image.