AutoMapper icon indicating copy to clipboard operation
AutoMapper copied to clipboard

AutoMapperJs is not defined

Open nartc opened this issue 7 years ago • 3 comments

Hi,

I've been trying to get automapper-ts to work with my Node Express backend. Everything works fine but I can't seem to implement external Profile files.

As seen in the screenshot, I keep getting AutoMapperJs is not defined. Not sure how to resolve this.

UserProfile.ts UserProfile.ts

Mapper.ts (I took out config.addProfile(new UserProfile()), if I leave it in, it would give me the error stated above) Mapper.ts which works fine

export class UserController extends BaseController {

    private _userRepository: IUserRepository = new UserRepository(User);
    private _autoMapper: Mapper = new Mapper();

    @Post('register')
    async register(@Body() newUserParams: NewUserParams): Promise<UserVm> {
        // ...more code here, simplified
        const user = await this._userRepository.create(newUser);
        const result: UserVm = this._autoMapper.mapper.map('IUser', 'UserVm', user.toJSON());
        return <UserVm>result;
    }
}

The above block is where I implemented automapper-ts and it's working beautifully. Now I'm thinking it would be nicer if I can get the Profile to work. Any suggestions?

nartc avatar Feb 24 '18 05:02 nartc

+1

Sir-J avatar Aug 01 '18 09:08 Sir-J

I have similar issue when trying to create custom converter

import { Page } from 'page/models/page.model';
import { PageVm } from 'page/models/view-models/page-vm.model';
import 'automapper-ts';

export class PageToPageVmConverter extends AutoMapperJs.TypeConverter {
  public convert(resolutionContext: AutoMapperJs.IResolutionContext): PageVm {
    const source = <Page>resolutionContext.sourceValue;
...

it gives the error

export class PageToPageVmConverter extends AutoMapperJs.TypeConverter {
                                           ^
ReferenceError: AutoMapperJs is not defined

rasikas avatar Aug 07 '18 23:08 rasikas

Same problem. Has anybody solved?

aslanovsergey avatar Jan 17 '19 13:01 aslanovsergey