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.

Adding this plugin to the plugin list breaks other Babel functionality

See original GitHub issue

Hi @leonardfactory, I noticed that when I add this plugin to my plugin list it breaks the other transformations in the config. I get this error message when it’s in there:

C:\Users\Robbie\Code\ginger\src\backend\resolvers\RecipeResolver.ts:1       
(function (exports, require, module, __filename, __dirname) { import {      
                                                                     ^      

SyntaxError: Unexpected token {

This is the same error message I get if I do not use Babel at all (or remove the react-app preset). If I don’t use the plugin, metadata reflection doesn’t work (and TypeORM gives me errors) but everything else does. My package.json babel config is this:

"babel": {
    "plugins": [
      "babel-plugin-transform-typescript-metadata",
      "@babel/plugin-proposal-optional-chaining",
      "@babel/plugin-proposal-nullish-coalescing-operator"
    ],
    "presets": [
      "react-app"
    ]
  }

If you need more information, my project repository is here: https://github.com/RobbieGM/ginger Thanks for your help!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wthocommented, Dec 11, 2019

Hey, I think you need at least the preset @babel/preset-typescript for this to work, probably even @babel/plugin-proposal-decorators and @babel/plugin-proposal-class-properties.

See the usage section for more.

Don’t forget to close this issue, if this helped you. Cheers!

0reactions
RobbieGMcommented, Dec 12, 2019

It works just fine the way it’s configured when run with ts-node but breaks when babel is involved. I’ll give it a try with direct entity class assignment as described. Also, @wtho TypeORM uses decorators and reflect-metadata magic to read types from sources. An example of a class written for TypeORM:

@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;

    @Column()
    lastName: string;

    @Column()
    age: number;

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins List - Babel.js
JavaScript. TC39 Proposals. decorators · do-expressions · duplicate-named-capturing-groups-regex · export-default-from · export-namespace-from · function- ...
Read more >
Options - Babel.js
Primary options; Config Loading options; Plugin and Preset configuration ... This option allows users to provide a list of other packages that should...
Read more >
babel/preset-env
@babel/preset-env takes any target environments you've specified and checks them against its mappings to compile a list of plugins and passes it to...
Read more >
babel/plugin-transform-typescript
This plugin adds support for the types syntax used by the TypeScript programming language. However, this plugin does not add the ability to...
Read more >
Upgrade to Babel 7 (API)
Dropped use of add-module-exports plugin on Babel packages. This had to be used earlier to prevent a breaking change with our exports. If...
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