Skip to content

question: Uncaught ReferenceError: exports is not defined when using in browser #529

@wSedlacek

Description

@wSedlacek

Description

The following error occurs when attempting to use class-transformer in my project.

Uncaught ReferenceError: exports is not defined

Additionally the following warning is shown in the terminal.

Warning: /libs/core/feature-components/src/core/fs-component.decorator.ts depends on 'class-transformer'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Minimal code-snippet showcasing the problem
The error occurs on import.

import {} from 'class-transformer'

Expected behavior

Imports to use es5/es2015 formats when in the browser

Actual behavior

CommonJS import appears to be used.

Additional context

My configuration for this project is a little, special. I am rendering React Native Web inside of an Angular project. This is requiring me to use Babel on top of the Angular Webpack configuration. From what I can tell this kills commonjs, not entirely sure why. I attempted to use some babel plugins to correct this and using babel-plugin-transform-commonjs works so long as I use the default import of class-transformer but a few (such as @Type() end up on the default export.

In any case the solution appears to be just to ship ES Modules, which appears to already be planned, just not released yet.

Added in 26b5dac. It will be included in the next release.
Originally posted by @NoNameProvided in #344 (comment)

So my question is when I can expect this next release?
Can a beta version be released that I could play with in the mean time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions