mapper icon indicating copy to clipboard operation
mapper copied to clipboard

Uncaught TypeError: classes_1.classes is not a function

Open LotuxPunk opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the issue

Hello, I have a library that I've compiled and I'm trying to run it in a ReactJS application.

This library uses AutoMapper with the classes strategy, and during startup, there are no compilation issues. However, once on the web console, the following error occurs:

Uncaught TypeError: classes_1.classes is not a function
    node_modules bundle.js:49154
    factory react refresh:6
    Webpack 39
mapper.ts:20
    js mapper.ts:20
    factory react refresh:6
    Webpack 39

The code in my library is similar (if not identical) to the documentation:

import {classes as classesFunction} from "@automapper/classes";
import {CamelCaseNamingConvention, createMapper, Mapper} from "@automapper/core";

export const mapper: Mapper = createMapper({
    strategyInitializer: classesFunction(),
    namingConventions: {
        source: new CamelCaseNamingConvention(),
        destination: new CamelCaseNamingConvention(),
    },
})

The result of the compilation:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

const classes_1 = require("@automapper/classes");
const core_1 = require("@automapper/core");
exports.mapper = (0, core_1.createMapper)({
    strategyInitializer: (0, classes_1.classes)(),
    namingConventions: {
        source: new core_1.CamelCaseNamingConvention(),
        destination: new core_1.CamelCaseNamingConvention(),
    },
});

Do you have any insights regarding this issue? Thank you in advance!

Models/DTOs/VMs

No response

Mapping configuration

No response

Steps to reproduce

No response

Expected behavior

ReactJS application to work without any log errors

Screenshots

No response

Minimum reproduction code

No response

Package

  • [ ] I don't know.
  • [X] @automapper/core
  • [X] @automapper/classes
  • [ ] @automapper/nestjs
  • [ ] @automapper/pojos
  • [ ] @automapper/mikro
  • [ ] @automapper/sequelize
  • [ ] Other (see below)

Other package and its version

No response

AutoMapper version

8.7.7

Additional context

NodeJS 18.6 MacOS 13

LotuxPunk avatar Jun 26 '23 09:06 LotuxPunk

Same here !

gwen1230 avatar Jul 19 '23 13:07 gwen1230

Found solution : https://github.com/facebook/create-react-app/issues/12700.

Create-react-app doesn't support cjs files.

gwen1230 avatar Jul 21 '23 06:07 gwen1230