leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler
MIT License
215 stars 17 forks source link

Unexpected token problem #32

Closed jelling closed 3 years ago

jelling commented 4 years ago

I may be barking up the wrong tree but is the library intended to fix the issue where TypeORM will not seem to work with Next.JS.

The error I get is:

/Users/jelling/dev/pw/longboard/next-js/jon/entities/person.ts:1
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
       ^

SyntaxError: Unexpected token {

I have worked with TypeORM extensively and typically this is because the code is expecting Javascript / the project needs to be run with ts-node. But this happens even when running npm run start after running npm run build and all of the TS should be JS at that point.

A zip of my project is attached.

nextjs typeorm wtf.zip

leonardfactory commented 4 years ago

Please, attach detail of your babel config & package.json. Thank you

dgurns commented 3 years ago

Having perhaps a related issue here.

Error:

Syntax error: Support for the experimental syntax 'decorators-legacy' isn't currently enabled:

  2 | import { User } from 'api/entities/User';
  3 | 
> 4 | @Resolver()
.babelrc
...
{
  "presets": ["next/babel", "@babel/preset-typescript"],
  "plugins": [
    "babel-plugin-transform-typescript-metadata",
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ]
  ]
}
package.json
...
{
  "name": "",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@apollo/client": "^3.3.6",
    "apollo-server-micro": "^2.19.1",
    "autoprefixer": "^10.1.0",
    "class-validator": "^0.12.2",
    "graphql": "^15.4.0",
    "graphql-depth-limit": "^1.1.0",
    "micro": "^9.3.4",
    "next": "10.0.4",
    "pg": "^8.5.1",
    "postcss": "^8.2.1",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "reflect-metadata": "^0.1.13",
    "tailwindcss": "^2.0.2",
    "type-graphql": "^1.1.1",
    "typeorm": "^0.2.29"
  },
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/plugin-proposal-class-properties": "^7.12.1",
    "@babel/plugin-proposal-decorators": "^7.12.12",
    "@babel/preset-env": "^7.12.11",
    "@babel/preset-typescript": "^7.12.7",
    "@types/graphql-depth-limit": "^1.1.2",
    "@types/node": "^14.14.16",
    "@types/react": "^17.0.0",
    "babel-plugin-parameter-decorator": "^1.0.16",
    "babel-plugin-transform-typescript-metadata": "^0.3.1",
    "typescript": "^4.1.3"
  }
}

Thank you!

leonardfactory commented 3 years ago

@dgurns It seems to me that babel config is not correctly loaded. Issue arise from babel-decorator anyway, so it should be better to ask them