babel-plugin-transform-typescript-metadata icon indicating copy to clipboard operation
babel-plugin-transform-typescript-metadata copied to clipboard

ColumnTypeUndefinedError: Column type for Exercise#name is not defined and cannot be guessed.

Open roberthobblebottom opened this issue 2 years ago • 2 comments

Despite installing this plugin, I think I still have the same problem. Help is appreciated but honestly I want to give up.

ColumnTypeUndefinedError: Column type for Exercise#name is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.

Exercise.tsx

import {Entity,Column, PrimaryGeneratedColumn} from "typeorm/browser";


@Entity("Exercise")
export class Exercise{

    @PrimaryGeneratedColumn()
    id!:number;

    @Column()
    name!: Text;

    @Column()
    notes:Text;

    @Column()
    imageJSON:Text;
}

.babelrc

{
    "plugins": [
      "babel-plugin-transform-typescript-metadata",
      ["@babel/plugin-proposal-decorators", { "legacy": true }],
      ["@babel/plugin-proposal-class-properties", { "loose": true }],
    ],
    "presets": [
      "@babel/preset-typescript"
    ]
  }

snippet of package.json

...

  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/node": "^18.0.0",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.66.13",
    "babel-plugin-transform-typescript-metadata": "^0.2.2",
    "typescript": "~4.3.5"
  },
...

roberthobblebottom avatar Jul 01 '22 18:07 roberthobblebottom

Okay I explicitly mentioned their types in the decorator, I guess that error seems to go away.

roberthobblebottom avatar Jul 06 '22 02:07 roberthobblebottom

Hello, are you sure that you imported reflect-metadata at the entrypoint of your application? It's a common issue.

leonardfactory avatar Sep 21 '22 10:09 leonardfactory