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.

Parser `decorators` plugin option `decoratorsBeforeExport` no longer defaulting

See original GitHub issue

Bug Report

Current Behavior In a recent v7 release (maybe even the final?), the parser decorators plugin option decoratorsBeforeExport no longer defaults as it used to.

const { parse } = require('@babel/core')

const result = parse(code, {
  parserOpts: {
    plugins: [
      'decorators'
    ]
  }
})

Results in an error:

/Users/jaydenseric/Sites/demo/node_modules/@babel/core/lib/transformation/normalize-file.js:209
    throw err;
    ^

Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean.

This is unexpected, as the decoratorsBeforeExport option is meant to default to false. Manually providing the same value as the supposed default works:

  const result = parse(code, {
    parserOpts: {
      plugins: [
-       'decorators'
+       ['decorators', { decoratorsBeforeExport: false }]
      ]
    }
  })

Expected behavior/code A clear and concise description of what you expected to happen (or code).

Babel Configuration (.babelrc, package.json, cli command)

N/A.

Environment

  • Babel version(s): v7.0.0
  • Node/npm version: Node.js v10.9.0, npm v6.4.0
  • OS: macOS
  • Monorepo [e.g. yes/no/Lerna]: No
  • How you are using Babel: [e.g. cli, register, loader]: API

Possible Solution

Additional context/Screenshots

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:29 (12 by maintainers)

github_iconTop GitHub Comments

17reactions
the-simiancommented, Aug 28, 2018

I’m struggling with this right now, when I set this:

      [
        require('@babel/plugin-proposal-decorators'),
        { decoratorsBeforeExport: false, legacy: true }
      ],

OR

      [
        require('@babel/plugin-proposal-decorators'),
        { decoratorsBeforeExport: true, legacy: true }
      ],

For both I get the same error 'decoratorsBeforeExport' can't be used with legacy decorators.

if I remove the legacy flag, like this:

      [
        require('@babel/plugin-proposal-decorators'),
        { decoratorsBeforeExport: false }
      ],

I get “The new decorators proposal is not supported yet. You must pass the "legacy": true option to @babel/plugin-proposal-decorators”.

if I remove the decoratorsBeforeExport entirely and just do the legacy flag,

[require('@babel/plugin-proposal-decorators'), { legacy: true }],

I am able to proceed…

However this does now cause errors with using decorators and then using export default. I’m aware the spec is ‘still in flux’ but what is the way to configure this where I can use decorators like

@something
export default class MyClass

Is this no longer able to be done?

8reactions
Aszmelcommented, Jan 6, 2019

recently was getting problem with this error and installed npm install --save-dev @babel/plugin-proposal-decorators and setup "babel": { "plugins": [ [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ], "presets": [ "react-app" ] },

this run my code with some errors, but app was working, I’m a beginner, so hope this comment is relevant

Read more comments on GitHub >

github_iconTop Results From Across the Web

The decorators Plugin when .version is '2018-09' or not ...
The decorators Plugin when .version is '2018-09' or not specified, requires a 'decoratorsBeforeExport' option, whose value must be a boolean.
Read more >
babel/plugin-proposal-decorators
⚠️ If you specify the decoratorsBeforeExport option, version defaults to "2018-09" . decoratorsBeforeExport. This option: is disallowed when using version: " ...
Read more >
@babel/plugin-syntax-export-default-from - Package Manager
Fast, reliable, and secure dependency management.
Read more >
this experimental syntax requires enabling one of ... - You.com
ESLint Plugin Settings for VSCode (autofix on save, Jest aware, babel parser ... caused by using decorators before export default ... , which...
Read more >
@babel/core - NPM Package Versions - Socket
babel-helpers , babel-plugin-transform-destructuring ... #14695 [parser] Make decoratorsBeforeExport default to false (@nicolo-ribaudo).
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