question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: class_transformer_1.classToPlain is not a function - using 1.15.0-beta.10

See original GitHub issue

I’m not sure if this is an issue with 1.15.0-beta.10. I’ve upgraded my ORM app and added/modified the following in my package.json file:

"dependencies": {
    "@aws-sdk/client-dynamodb": "^3.131.0",
    "@aws-sdk/lib-dynamodb": "^3.131.0",
    "@typedorm/common": "1.15.0-beta.10",
    "@typedorm/core": "1.15.0-beta.10",
    "aws-crt": "^1.13.1",

...

I haven’t changed any other files (I’m not sure if i needed to?)

Everything builds fine, but at run time I get the following stack errors.

          "stacktrace": [
            "TypeError: class_transformer_1.classToPlain is not a function",
            "    at DocumentClientRequestTransformer.applyClassTransformerFormations (/path-to-my-app/packages/core/src/classes/transformer/base-transformer.ts:52:36)",
            "    at DocumentClientRequestTransformer.toDynamoEntity (/path-to-my-app/packages/core/src/classes/transformer/base-transformer.ts:94:31)",
            "    at DocumentClientRequestTransformer.toDynamoPutItem (/path-to-my-app/packages/core/src/classes/transformer/document-client-request-transformer.ts:136:31)",
            "    at EntityManager.<anonymous> (/path-to-my-app/packages/core/src/classes/manager/entity-manager.ts:198:55)",
            "    at Generator.next (<anonymous>)",
            "    at /path-to-my-app/lib/orm/node_modules/@typedorm/core/cjs/src/classes/manager/entity-manager.js:8:71",
            "    at new Promise (<anonymous>)",
            "    at __awaiter (/path-to-my-app/lib/orm/node_modules/@typedorm/core/cjs/src/classes/manager/entity-manager.js:4:12)",
            "    at EntityManager.create (/path-to-my-app/lib/orm/node_modules/@typedorm/core/cjs/src/classes/manager/entity-manager.js:35:16)",
            "    at /path-to-my-app/myapp/src/resolvers/mutation/createProduct.ts:17:70"
          ]

What’s kind of odd is the reference to the following file path that doesn’t exist:

/packages/core/src/classes/transformer/base-transformer.ts

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danieljarrett74commented, Jul 22, 2022
0reactions
danieljarrett74commented, Jul 27, 2022

Thanks @whimzyLive thats a great help. I currently use webpack to build the project which uses the module/package the the typedorm code is in. But I thought it might be easier to build this local module with rollup. And if it wasn’t for the following it would be ok 😃


I tried following your example on your forked repo and it built fine but when I included the built module in my project I got the error: ES modules is not supported

So then I tried to build it as a cjs with the following config (below) and everything worked fine, but at runtime the AUTO_GENERATE_ATTRIBUTE_STRATEGY.ISO_DATE isn’t working. As in when I do an insert the created and updated date for the following code don’t get created:

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.ISO_DATE,
  })
  createdAt!: string;

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.ISO_DATE,
    autoUpdate: true,
  })

rollup.config.js

import typescript from 'rollup-plugin-typescript2'
import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from "@rollup/plugin-node-resolve";
import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
	"input": "src/index.ts",
	"output": {
		"sourcemap": "true",
		"file": "dist/index.js",
		"format": "cjs"
	},
	"external": ["aws-sdk","uuid"],
	"plugins": [
		commonjs(
			{
				include: 'node_modules/**',
      ignoreGlobal: true
			}
		),
		typescript({ sourceMap: false }),
		nodeResolve({
			preferBuiltins: true		}),
		json(),
	],
	onwarn: function (warning) {
		// Skip certain warnings

		// should intercept ... but doesn't in some rollup versions
		if (warning.code === 'THIS_IS_UNDEFINED') { return; }

		if (warning.code === 'CIRCULAR_DEPENDENCY') { return; }

		// console.warn everything else
		console.warn(warning.message);
	}
};

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "strict": true,
    "esModuleInterop": true, 
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "declaration": true,
    "declarationDir": "./dist",
    "outDir": "./dist",
    "allowSyntheticDefaultImports":true,
    "skipLibCheck": true,
    "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
    "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
  },

  "include": ["src/**/*.ts", "dist/**/*.ts"]}

package.json

{
  "name": "orm",
  "version": "0.1.6",
  "main": "./dist/",
  "files": [
    "dist"
  ],
  "scripts": {
    "build": "rollup -c && npm pack"
  },
  "license": "MIT",
  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.131.0",
    "@aws-sdk/lib-dynamodb": "^3.131.0",
    "@typedorm/common": "1.15.0-beta.10",
    "@typedorm/core": "1.15.0-beta.10",
    "@types/node": "^18.0.3",
    "aws-crt": "^1.13.1",
    "aws-sdk": "^2.1178.0",
    "reflect-metadata": "^0.1.13",
    "rollup-plugin-node-polyfills": "^0.2.1",
    "ts-node": "^10.8.1",
    "typescript": "^4.7.4"
  },
  "devDependencies": {
    "rollup": "^2.77.0",
    "@rollup/plugin-commonjs": "^22.0.1",
    "@rollup/plugin-json": "^4.1.0",
    "@rollup/plugin-node-resolve": "^13.3.0",
    "rollup-plugin-typescript2": "^0.32.1",
    "@rollup/plugin-typescript": "^8.3.3"
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

classToPlain is not a function · Issue #8637 · nestjs/nest - GitHub
Steps to reproduce. Copy the Serializer example from Nestjs; Run the application; Make a request to a controller, see error. Expected behavior.
Read more >
using validation pipe in nestjs gives me an classTransformer ...
problem solved. due to recent update, class-transformer@0.5.0 makes an error when used in validationPipe of nestJS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found