babel: beta48 decorators regression

Using @babel/preset-stage-2 with decoratorsLegacy on 47 was fine, with 48 it complains that it doesn’t see the transform:

SyntaxError: src/effects/poof.js: Decorators transform is necessary.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 22 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Can you try putting '@babel/plugin-proposal-decorators', before '@babel/plugin-proposal-class-properties',?

thanks @nicolo-ribaudo ! I can confirm, beta.49 fixes it!

just a note for everyone still experiencing the issue:

decorator-plugin has to be loaded BEFORE class-properties-plugin now. otherwise the error still appears.

Alright, I’ve tracked down the primary issue causing the

Decorators transform is necessary.

error. It appears that validation added in the current beta is catching an edge case that was introduced way back in beta.37, but didn’t actually cause any issues.

@nicolo-ribaudo The issue is the loss of this visitor: https://github.com/babel/babel/commit/b93184e430c5785dad197f53f73904a2a06fc1ed#diff-9edac3b7447086939a48e78f20989ef8L218 in favor of this logic https://github.com/babel/babel/commit/b93184e430c5785dad197f53f73904a2a06fc1ed#diff-9edac3b7447086939a48e78f20989ef8R230 that reaches into the parent. Because the transform reaches into the parent to replace the parent instead of itself, traversal of the AST has already reached the class declaration by the time it is replaced. This means that even though it is replaced, the class property transform will still try to process it, which means the new validation added in https://github.com/babel/babel/pull/7842/files#diff-58f25136e574c8f618d51c7e6a454270R275 will throw.

The best fix, in my mind, would be to go back to using a ExportDefaultDeclaration visitor there if we can.

I don’t have to jump on this now, but I can give it a shot tomorrow if you haven’t gotten to it yet.

@dnalborczyk Can confirm this simple change worked for me. Would be great to add this to the babel “decorator plugin missing” error message.

Ok Maybe that was the wrong trace, let me double check on that…

I’ll go back up to .48 and run my scenario again and try to get a trace

Edit: Well I just upgraded everything back to .48 and now I am not getting the same issue. I must have had mismatched dependencies earlier, just like @hzoo suggested

I think I’m experiencing this as well, I was getting the error: Support for the experimental syntax 'decorators' isn't currently enabled, and then it was prompting me to add the @babel/plugin-proposal-decorators package

I do this (and I am mindful to add this before the proposal-class-properties plugin), and then it says I need to set the legacy flag to true. So I do this and then…

i get the first error again, in an endless loop.

I am setting back to .47 to see if this resolves my issue.

so to be clear I was using

    "@babel/core": "7.0.0-beta.48",
    "@babel/plugin-proposal-decorators": "7.0.0-beta.48",
    "@babel/plugin-proposal-class-properties": "7.0.0-beta.48",

putting them in this order:

    [require('@babel/plugin-proposal-decorators'), { legacy: true }],
    [require('@babel/plugin-proposal-class-properties').default,{loose: true}],

in my plugins

I’m having the same problem. switching the order didn’t help.

reverting @babel/plugin-proposal-class-properties to beta 47 worked.

update:

commenting the following out worked as well: https://github.com/babel/babel/blob/master/packages/babel-plugin-proposal-class-properties/src/index.js#L273

          if (decorators && decorators.length > 0) {
            throw path.buildCodeFrameError("Decorators transform is necessary.");
          }

decorators is undefined.